diff --git a/patches/golden-layout+1.5.9.patch b/patches/golden-layout+1.5.9.patch index 30336fddc..247cee8c2 100644 --- a/patches/golden-layout+1.5.9.patch +++ b/patches/golden-layout+1.5.9.patch @@ -1,14 +1,13 @@ diff --git a/node_modules/golden-layout/dist/goldenlayout.js b/node_modules/golden-layout/dist/goldenlayout.js -index 736f9ec..7a04007 100644 +index 736f9ec..c898450 100644 --- a/node_modules/golden-layout/dist/goldenlayout.js +++ b/node_modules/golden-layout/dist/goldenlayout.js -@@ -1,3 +1,5 @@ -+import $ from 'jquery'; -+ +@@ -1,3 +1,4 @@ ++var $ = require('jquery'); (function($){var lm={"config":{},"container":{},"controls":{},"errors":{},"items":{},"utils":{}}; lm.utils.F = function() { }; -@@ -3703,7 +3705,11 @@ lm.items.Component = function( layoutManager, config, parent ) { +@@ -3703,7 +3704,11 @@ lm.items.Component = function( layoutManager, config, parent ) { this.isComponent = true; this.container = new lm.container.ItemContainer( this.config, this, layoutManager ); @@ -21,7 +20,7 @@ index 736f9ec..7a04007 100644 this.element = this.container._element; }; -@@ -5336,4 +5342,4 @@ lm.utils.copy( lm.utils.ReactComponentHandler.prototype, { +@@ -5336,4 +5341,4 @@ lm.utils.copy( lm.utils.ReactComponentHandler.prototype, { var props = $.extend( defaultProps, this._container._config.props ); return React.createElement( this._reactClass, props ); } diff --git a/tsconfig.base.json b/tsconfig.base.json index b8bd70e3c..19bd8e4d4 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -6,6 +6,7 @@ "importHelpers": true, /* Module resolution */ "esModuleInterop": true, + "allowSyntheticDefaultImports": true, /* Other options */ "forceConsistentCasingInFileNames": true, "skipLibCheck": true, diff --git a/tsconfig.frontend.json b/tsconfig.frontend.json index 57a782741..c73952481 100644 --- a/tsconfig.frontend.json +++ b/tsconfig.frontend.json @@ -8,7 +8,7 @@ "strictPropertyInitialization": false, "lib": ["dom", "es5", "dom.iterable"] }, - "exclude": [ + "exclude": [ "out", "test", "etc", diff --git a/vite-plugin-hashed-pug.ts b/vite-plugin-hashed-pug.ts index 6467dd25f..1ede6d0ad 100644 --- a/vite-plugin-hashed-pug.ts +++ b/vite-plugin-hashed-pug.ts @@ -23,12 +23,17 @@ // POSSIBILITY OF SUCH DAMAGE. import {execSync} from 'node:child_process'; -import * as fs from 'node:fs/promises'; +import * as crypto from 'node:crypto'; import * as path from 'node:path'; -import {getHashDigest} from 'loader-utils'; import * as pug from 'pug'; import {Plugin, createLogger} from 'vite'; +function getHashDigest(data: string) { + const hash = crypto.createHash('sha256'); + hash.update(data); + return hash.digest('hex').substring(0, 16); +} + const HASHES = { cookies: '08712179739d3679', privacy: 'c0dad1f48a56b761', @@ -47,10 +52,12 @@ export type VitePluginHashedPugOptions = { */ export function vitePluginHashedPug({useGit}): Plugin { const logger = createLogger('info', { - prefix: 'vite-plugin-hashed-pug', + prefix: '[vite-plugin-hashed-pug]', }); if (!useGit) { logger.warn('vite-plugin-hashed-pug is configured to not use git: file contents will be wrong'); + } else { + logger.info('vite-plugin-hashed-pug is using git directory to determine last commit and changes'); } const execGit = useGit ? execGitSync : () => 'no-git-available'; return { @@ -59,6 +66,7 @@ export function vitePluginHashedPug({useGit}): Plugin { if (!id.endsWith('.pug')) { return null; } + console.info('transforming pug file', id); const filename = path.basename(id); const lastTime = execGit(`git log -1 --format=%cd "${id}"`).trimEnd(); const lastCommit = execGit(`git log -1 --format=%h "${id}"`).trimEnd(); @@ -67,24 +75,22 @@ export function vitePluginHashedPug({useGit}): Plugin { .map(line => line.match(/(?\w+) (?.*)/)) .filter(x => x) .map(match => match?.groups ?? {}); - const content = await fs.readFile(id, 'utf-8'); - const pugModule = pug.compile(content, {filename: id}); + const pugModule = pug.compile(src, {filename: id}); // When calculating the hash we ignore the hard-to-predict values like lastTime and lastCommit, else every // time we merge changes in policies to main we get a new hash after checking in, and that breaks the build. const htmlTextForHash = pugModule({gitChanges, lastTime: 'some-last-time', lastCommit: 'some-last-commit'}); - const hashDigest = getHashDigest(htmlTextForHash, 'sha256', 'hex', 16); + const hashDigest = getHashDigest(htmlTextForHash); const expectedHash = HASHES[filename]; if (useGit && expectedHash !== undefined && expectedHash !== hashDigest) { logger.warn(`Hash mismatch for ${filename}: expected ${expectedHash}, got ${hashDigest}`); logger.warn('If this was expected, update the hash in `vite-plugin-hashed-pug.ts`'); } - const html = pugModule({gitChanges, lastTime, lastCommit}); return { code: ` export default { - hash: '${hashDigest}', - text: \`${html}\`, + hash: ${JSON.stringify(hashDigest)}, + text: ${JSON.stringify(html)}, }; `.trim(), }; diff --git a/vite.config.ts b/vite.config.ts index 8f4c0b1a5..f430bde81 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -4,7 +4,8 @@ import * as url from 'node:url'; import {defineConfig} from 'vite'; import {vitePluginHashedPug} from './vite-plugin-hashed-pug.js'; -const hasGit = fss.existsSync(path.resolve(import.meta.url, '.git')); +const pwd = url.fileURLToPath(new URL('.', import.meta.url)); +const hasGit = fss.existsSync(path.join(pwd, '.git')); export default defineConfig({ plugins: [vitePluginHashedPug({useGit: hasGit})], @@ -17,6 +18,7 @@ export default defineConfig({ }, }, commonjsOptions: { + defaultIsModuleExports: true, include: [ /golden-layout/, /jquery/, @@ -28,10 +30,9 @@ export default defineConfig({ /file-saver/, /path-browserify/, /jszip/, + /lz-string/, + /monaco-vim/, ], }, }, - optimizeDeps: { - include: ['jquery'], - }, });