diff --git a/.gitea/workflows/docker-release.yml b/.gitea/workflows/docker-release.yml index 7cfb676..b657b6c 100644 --- a/.gitea/workflows/docker-release.yml +++ b/.gitea/workflows/docker-release.yml @@ -69,6 +69,53 @@ jobs: timeout-minutes: 15 run: npm run build + - name: Microfrontend - nessun import di vue nel dist + timeout-minutes: 5 + shell: bash + # BLOCCANTE (devops/shared-actions#31). Nella shell un import di vue rimasto + # nel dist non si risolve e il modulo non si carica, con build e test verdi. + run: | + node - <<'FINE' + const fs = require('fs') + const path = require('path') + + // Solo i microfrontend: la shell fornisce vue, quindi nel loro dist non deve restarne un import. + if (!fs.existsSync('dist/mfe-entry.js')) { + console.log('Nessun dist/mfe-entry.js: controllo non applicabile.') + process.exit(0) + } + + // Ancorata a inizio riga, ';' o '}': un esempio in un commento (' * import ...') non e' un import. + const IMPORT = /(?:^|[;}])[ \t]*(?:import|export)\b[^;"'()=]*?(?:\bfrom\s*)?["'](?:vue|vue-router)["']/m + + const prove = [ + ['import "vue";', true], + ['var a=1;import{ref as r}from"vue";', true], + ["import {\n ref,\n} from 'vue'", true], + ['export * from "vue-router"', true], + [" * import { createApp } from 'vue'", false], + ['// import "vue"', false], + ['const s = "import x from \'vue\'"', false], + ['import{a}from"vue-i18n";', false], + ] + for (const [testo, atteso] of prove) { + if (IMPORT.test(testo) !== atteso) { + console.log(`::error::Controllo non affidabile: caso di prova fallito (${JSON.stringify(testo)}).`) + process.exit(1) + } + } + + const file = fs.readdirSync('dist', { recursive: true }).filter((f) => /\.m?js$/.test(f)) + const difettosi = file.filter((f) => IMPORT.test(fs.readFileSync(path.join('dist', f), 'utf8'))) + if (difettosi.length) { + console.log("::error::Il dist del microfrontend importa ancora 'vue' o 'vue-router': nella shell il modulo non si carica.") + for (const f of difettosi) console.log(' dist/' + f) + console.log('Controllare il plugin external-globals in vite.config: deve trattare anche l\'import senza nomi (import "vue";).') + process.exit(1) + } + console.log(`Nessun import di vue nel dist (${file.length} file JavaScript).`) + FINE + - name: Test timeout-minutes: 20 run: npm run test diff --git a/.gitea/workflows/quality-gates.yml b/.gitea/workflows/quality-gates.yml index 542ffcc..896e68d 100644 --- a/.gitea/workflows/quality-gates.yml +++ b/.gitea/workflows/quality-gates.yml @@ -541,6 +541,53 @@ jobs: timeout-minutes: 15 run: npm run build + - name: Microfrontend - nessun import di vue nel dist + timeout-minutes: 5 + shell: bash + # BLOCCANTE (devops/shared-actions#31). Nella shell un import di vue rimasto + # nel dist non si risolve e il modulo non si carica, con build e test verdi. + run: | + node - <<'FINE' + const fs = require('fs') + const path = require('path') + + // Solo i microfrontend: la shell fornisce vue, quindi nel loro dist non deve restarne un import. + if (!fs.existsSync('dist/mfe-entry.js')) { + console.log('Nessun dist/mfe-entry.js: controllo non applicabile.') + process.exit(0) + } + + // Ancorata a inizio riga, ';' o '}': un esempio in un commento (' * import ...') non e' un import. + const IMPORT = /(?:^|[;}])[ \t]*(?:import|export)\b[^;"'()=]*?(?:\bfrom\s*)?["'](?:vue|vue-router)["']/m + + const prove = [ + ['import "vue";', true], + ['var a=1;import{ref as r}from"vue";', true], + ["import {\n ref,\n} from 'vue'", true], + ['export * from "vue-router"', true], + [" * import { createApp } from 'vue'", false], + ['// import "vue"', false], + ['const s = "import x from \'vue\'"', false], + ['import{a}from"vue-i18n";', false], + ] + for (const [testo, atteso] of prove) { + if (IMPORT.test(testo) !== atteso) { + console.log(`::error::Controllo non affidabile: caso di prova fallito (${JSON.stringify(testo)}).`) + process.exit(1) + } + } + + const file = fs.readdirSync('dist', { recursive: true }).filter((f) => /\.m?js$/.test(f)) + const difettosi = file.filter((f) => IMPORT.test(fs.readFileSync(path.join('dist', f), 'utf8'))) + if (difettosi.length) { + console.log("::error::Il dist del microfrontend importa ancora 'vue' o 'vue-router': nella shell il modulo non si carica.") + for (const f of difettosi) console.log(' dist/' + f) + console.log('Controllare il plugin external-globals in vite.config: deve trattare anche l\'import senza nomi (import "vue";).') + process.exit(1) + } + console.log(`Nessun import di vue nel dist (${file.length} file JavaScript).`) + FINE + - name: Test timeout-minutes: 20 run: npm run test