@travetto/pack 4.0.0-rc.0 → 4.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -244,7 +244,7 @@ echo "FROM node:20-alpine" > $DIST/Dockerfile
244
244
  echo "RUN which useradd && (groupadd --gid 2000 app && useradd -u 2000 -g app app) || (addgroup -g 2000 app && adduser -D -G app -u 2000 app)" >> $DIST/Dockerfile
245
245
  echo "RUN mkdir /app && chown app:app /app" >> $DIST/Dockerfile
246
246
  echo "COPY --chown=\"app:app\" . /app" >> $DIST/Dockerfile
247
- echo "ENV NODE_OPTIONS=\"--disable-proto=delete\"" >> $DIST/Dockerfile
247
+ echo "ENV NODE_OPTIONS=\"\"" >> $DIST/Dockerfile
248
248
  echo "USER app" >> $DIST/Dockerfile
249
249
  echo "WORKDIR /app" >> $DIST/Dockerfile
250
250
  echo "ENTRYPOINT [\"/app/todo-app.sh\"]" >> $DIST/Dockerfile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "4.0.0-rc.0",
3
+ "version": "4.0.0-rc.2",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -25,15 +25,15 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@rollup/plugin-commonjs": "^25.0.7",
28
- "@rollup/plugin-json": "^6.0.1",
28
+ "@rollup/plugin-json": "^6.1.0",
29
29
  "@rollup/plugin-node-resolve": "^15.2.3",
30
30
  "@rollup/plugin-terser": "^0.4.4",
31
- "@travetto/base": "^4.0.0-rc.0",
32
- "@travetto/terminal": "^4.0.0-rc.0",
33
- "rollup": "^4.6.1"
31
+ "@travetto/base": "^4.0.0-rc.2",
32
+ "@travetto/terminal": "^4.0.0-rc.2",
33
+ "rollup": "^4.9.6"
34
34
  },
35
35
  "peerDependencies": {
36
- "@travetto/cli": "^4.0.0-rc.0"
36
+ "@travetto/cli": "^4.0.0-rc.2"
37
37
  },
38
38
  "peerDependenciesMeta": {
39
39
  "@travetto/cli": {
@@ -39,10 +39,7 @@ export class PackConfigUtil {
39
39
  */
40
40
  static dockerEnvVars(cfg: DockerPackConfig): string {
41
41
  return [
42
- `ENV NODE_OPTIONS="${[
43
- '--disable-proto=delete', // Security enforcement
44
- ...(cfg.sourcemap ? ['--enable-source-maps'] : []),
45
- ].join(' ')}"`,
42
+ `ENV NODE_OPTIONS="${[...(cfg.sourcemap ? ['--enable-source-maps'] : [])].join(' ')}"`,
46
43
  ].join('\n');
47
44
  }
48
45
 
@@ -7,20 +7,31 @@ import { ManifestModule, ManifestModuleUtil, NodeModuleType, path, RuntimeIndex,
7
7
  import { EnvProp } from '@travetto/base';
8
8
 
9
9
  // eslint-disable-next-line @typescript-eslint/naming-convention
10
- function __envImport(mod: typeof fs, file: string): void {
11
- if (process.env.TRV_MODULE) { return; }
12
- try {
13
- mod.readFileSync(file, 'utf8')
14
- .split('\n')
15
- .map(x => x.match(/\s*(?<key>[^ =]+)\s*=\s*(?<value>\S+)/)?.groups)
16
- .filter((x): x is Exclude<typeof x, null | undefined> => !!x)
17
- .forEach(x => process.env[x.key] = x.value);
18
- } catch { }
10
+ function __init(mod: typeof fs, file?: string, freezeProto?: boolean): void {
11
+ if (freezeProto !== false) {
12
+ // @ts-expect-error -- Lock to prevent __proto__ pollution in JSON
13
+ const objectProto = Object.prototype.__proto__;
14
+ Object.defineProperty(Object.prototype, '__proto__', {
15
+ get() { return objectProto; },
16
+ set(val) { Object.setPrototypeOf(this, val); }
17
+ });
18
+ }
19
+
20
+ if (file) {
21
+ if (process.env.TRV_MODULE) { return; }
22
+ try {
23
+ mod.readFileSync(file, 'utf8')
24
+ .split('\n')
25
+ .map(x => x.match(/\s*(?<key>[^ =]+)\s*=\s*(?<value>\S+)/)?.groups)
26
+ .filter((x): x is Exclude<typeof x, null | undefined> => !!x)
27
+ .forEach(x => process.env[x.key] = x.value);
28
+ } catch { }
29
+ }
19
30
  }
20
31
 
21
- const INTRO = (envFile: string | undefined): Record<NodeModuleType, string[]> => ({
22
- commonjs: !envFile ? [] : [`(${__envImport.toString()})(require('node:fs'), '${envFile}')`],
23
- module: !envFile ? [] : [`(${__envImport.toString()})(await import('node:fs'), '${envFile}')`]
32
+ const INTRO = (envFile: string | undefined, sourceMap?: boolean): Record<NodeModuleType, string> => ({
33
+ commonjs: `(${__init.toString()})(require('node:fs'), '${envFile}', ${!!sourceMap})`,
34
+ module: `(${__init.toString()})(await import('node:fs'), '${envFile}', ${!!sourceMap})`
24
35
  });
25
36
 
26
37
  function getFilesFromModule(m: ManifestModule): string[] {
@@ -44,7 +55,7 @@ export function getOutput(): OutputOptions {
44
55
  return {
45
56
  format,
46
57
  interop: format === 'commonjs' ? 'auto' : undefined,
47
- intro: INTRO(new EnvProp('BUNDLE_ENV_FILE').val)[format].join(';\n'),
58
+ intro: INTRO(new EnvProp('BUNDLE_ENV_FILE').val)[format],
48
59
  sourcemapPathTransform: (src, map): string =>
49
60
  path.resolve(path.dirname(map), src).replace(`${RuntimeContext.workspace.path}/`, ''),
50
61
  sourcemap: new EnvProp('BUNDLE_SOURCEMAP').bool ?? false,
@@ -88,7 +88,7 @@ export class PackOperation {
88
88
  yield bundleCommand;
89
89
  yield ActiveShellCommand.chdir(path.cwd());
90
90
  } else {
91
- await PackUtil.runCommand(bundleCommand, { cwd, env });
91
+ await PackUtil.runCommand(bundleCommand, { cwd, env: { ...process.env, ...env } });
92
92
  const stat = await fs.stat(path.resolve(cfg.workspace, cfg.mainFile));
93
93
  yield [cliTpl`${{ title: 'Bundled Output ' }} ${{ identifier: 'sizeKb' }}=${{ param: Math.trunc(stat.size / 2 ** 10) }}`];
94
94
  }
@@ -214,7 +214,7 @@ export class PackOperation {
214
214
  if (cfg.ejectFile) {
215
215
  yield [...Object.entries(env).map(([k, v]) => `${k}=${v}`), ...cmd];
216
216
  } else {
217
- await PackUtil.runCommand(cmd, { env });
217
+ await PackUtil.runCommand(cmd, { env: { ...process.env, ...env } });
218
218
  }
219
219
  }
220
220
 
@@ -1,7 +1,8 @@
1
1
  import fs from 'node:fs/promises';
2
+ import { spawn, SpawnOptions } from 'node:child_process';
2
3
 
3
4
  import { path, RuntimeIndex } from '@travetto/manifest';
4
- import { AppError, ExecUtil, ExecutionOptions } from '@travetto/base';
5
+ import { AppError, ExecUtil } from '@travetto/base';
5
6
 
6
7
  import { ActiveShellCommand } from './shell';
7
8
 
@@ -23,7 +24,7 @@ export class PackUtil {
23
24
  */
24
25
  static async copyRecursive(src: string, dest: string, ignore = false): Promise<void> {
25
26
  const [cmd, ...args] = ActiveShellCommand.copyRecursive(src, dest);
26
- const res = await ExecUtil.spawn(cmd, args, { catchAsResult: true }).result;
27
+ const res = await ExecUtil.getResult(spawn(cmd, args, { shell: false }), { catch: true });
27
28
  if (res.code && !ignore) {
28
29
  throw new Error(`Failed to copy ${src} to ${dest}`);
29
30
  }
@@ -65,12 +66,13 @@ export class PackUtil {
65
66
  /**
66
67
  * Track result response
67
68
  */
68
- static async runCommand(cmd: string[], opts: ExecutionOptions = {}): Promise<string> {
69
- const { valid, code, stderr, message, stdout } = await ExecUtil.spawn(cmd[0], cmd.slice(1), {
70
- stdio: [0, 'pipe', 'pipe', 'ipc'],
69
+ static async runCommand(cmd: string[], opts: SpawnOptions = {}): Promise<string> {
70
+ const { valid, code, stderr, message, stdout } = await ExecUtil.getResult(spawn(cmd[0], cmd.slice(1), {
71
+ stdio: [0, 'pipe', 'pipe'],
72
+ shell: false,
71
73
  ...opts,
72
- catchAsResult: true
73
- }).result;
74
+ }), { catch: true });
75
+
74
76
  if (!valid) {
75
77
  process.exitCode = code;
76
78
  throw new AppError(stderr || message || 'An unexpected error has occurred');