Rigidify code replacement by using Lodash templates.

This commit is contained in:
Bryce Gibson
2021-09-18 11:20:05 +10:00
parent bbaa63767d
commit fc09a7d903
6 changed files with 1287 additions and 1549 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ import { resolveSync } from 'resolve-dependencies'
const caw = require('caw')
const c = process.platform === 'win32' ? chalk.constructor({ enabled: false }) : chalk
export const version = '{{replace:0}}'
export const version = '{{ version }}'
export interface NexePatch {
(compiler: NexeCompiler, next: () => Promise<void>): Promise<void>
+4 -4
View File
@@ -58,7 +58,7 @@ export default async function main(compiler: NexeCompiler, next: () => Promise<v
fileLines.splice(
location.start.line,
0,
'{{replace:lib/fs/bootstrap.js}}' +
'{{ file("lib/fs/bootstrap.js") }}' +
'\n' +
(semverGt(version, '11.99') ? 'expandArgv1 = false;\n' : '')
)
@@ -69,13 +69,13 @@ export default async function main(compiler: NexeCompiler, next: () => Promise<v
await compiler.replaceInFileAsync(
bootFile,
'initializeFrozenIntrinsics();',
'initializeFrozenIntrinsics();\n' + wrap('{{replace:lib/patches/boot-nexe.js}}')
'initializeFrozenIntrinsics();\n' + wrap('{{ file("lib/patches/boot-nexe.js") }}')
)
} else {
await compiler.replaceInFileAsync(
bootFile,
'initializePolicy();',
'initializePolicy();\n' + wrap('{{replace:lib/patches/boot-nexe.js}}')
'initializePolicy();\n' + wrap('{{ file("lib/patches/boot-nexe.js") }}')
)
}
await compiler.replaceInFileAsync(
@@ -102,7 +102,7 @@ export default async function main(compiler: NexeCompiler, next: () => Promise<v
} else {
await compiler.setFileContentsAsync(
'lib/_third_party_main.js',
'{{replace:lib/patches/boot-nexe.js}}'
'{{ file("lib/patches/boot-nexe.js") }}'
)
}
return next()
+1 -1
View File
@@ -6,7 +6,7 @@ export default async function (compiler: NexeCompiler, next: () => Promise<void>
compiler.shims.push(
wrap(
'' +
'{{replace:lib/fs/patch.js}}' +
'{{ file("lib/fs/patch.js") }}' +
'\nshimFs(process.__nexe)' +
`\n${compiler.options.fs ? '' : 'restoreFs()'}`
//TODO support only restoring specific methods