@travetto/pack 3.1.0-rc.2 → 3.1.0-rc.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "3.1.0-rc.2",
3
+ "version": "3.1.0-rc.4",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -1,26 +1,23 @@
1
1
  import type { OutputOptions } from 'rollup';
2
+ import { __importStar } from 'tslib';
3
+
2
4
  import type terser from '@rollup/plugin-terser';
3
5
 
4
6
  import { Env } from '@travetto/base';
5
7
  import { ManifestModule, ManifestModuleUtil, Package, path, RootIndex } from '@travetto/manifest';
6
8
 
7
- const INTRO = {
8
- commonjs: `
9
- try { globalThis.crypto = require('crypto'); } catch {}
10
- try { require('./.env.js')} catch {}
9
+ export const RUNTIME_MODULES = 'trv_node_modules';
11
10
 
12
- function __importStar(mod) {
13
- if (mod && mod.__esModule) return mod;
14
- var result = {};
15
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
16
- result['default'] = mod;
17
- return result;
18
- }
19
- `,
20
- module: `
21
- tyr{ globalThis.crypto = await import('crypto'); } catch {}
22
- try {await import('./.env.js')} catch {}
23
- `
11
+ const makeIntro = (doImport: (name: string) => string): string => `
12
+ try { (${doImport('child_process')}).execFileSync('mkdir -p node_modules/ && cp -r ${RUNTIME_MODULES}/* node_modules/', { shell:true}); } catch {}
13
+ try { globalThis.crypto = ${doImport('crypto')}; } catch {}
14
+ try { ${doImport('./.env.js')} } catch {}
15
+ `;
16
+
17
+ const INTRO = {
18
+ commonjs: `${makeIntro(v => `require('${v}')`)}
19
+ ${__importStar.toString().replace(/function([^(]+)/, 'function __importStar')}`,
20
+ module: makeIntro(v => `await import('${v}')`)
24
21
  };
25
22
 
26
23
  function getFilesFromModule(m: ManifestModule): string[] {
@@ -7,6 +7,7 @@ import { cliTpl } from '@travetto/cli';
7
7
  import { CommonPackConfig } from './types';
8
8
  import { PackUtil } from './util';
9
9
  import { ActiveShellCommand, ShellCommands } from './shell';
10
+ import { RUNTIME_MODULES } from './config';
10
11
 
11
12
  async function writeRawFile(file: string, contents: string, mode?: string): Promise<void> {
12
13
  await fs.writeFile(file, contents, { encoding: 'utf8', mode });
@@ -97,7 +98,7 @@ export class PackOperation {
97
98
  */
98
99
  static async * writePackageJson(cfg: CommonPackConfig): AsyncIterable<string[]> {
99
100
  const file = 'package.json';
100
- const pkg = { type: RootIndex.manifest.moduleType };
101
+ const pkg = { type: RootIndex.manifest.moduleType, main: `${cfg.mainName}.js` };
101
102
 
102
103
  yield* PackOperation.title(cfg, cliTpl`${{ title: 'Writing' }} ${{ path: file }}`);
103
104
 
@@ -233,6 +234,22 @@ export class PackOperation {
233
234
  }
234
235
  }
235
236
 
237
+ /**
238
+ * Duplicate node_modules
239
+ */
240
+ static async * duplicateNodeModules(cfg: CommonPackConfig): AsyncIterable<string[]> {
241
+ const src = path.resolve(cfg.workspace, 'node_modules');
242
+ const dest = path.resolve(cfg.workspace, RUNTIME_MODULES);
243
+
244
+ yield* PackOperation.title(cfg, cliTpl`${{ title: 'Creating a Copy of Node Modules' }} ${{ path: path.join('node_modules') }}`);
245
+
246
+ if (cfg.ejectFile) {
247
+ yield ActiveShellCommand.copyRecursive(src, dest);
248
+ } else {
249
+ await PackUtil.copyRecursive(src, dest);
250
+ }
251
+ }
252
+
236
253
  /**
237
254
  * Generate ZIP file for workspace
238
255
  */
@@ -242,9 +259,11 @@ export class PackOperation {
242
259
 
243
260
  if (cfg.ejectFile) {
244
261
  yield ActiveShellCommand.chdir(cfg.workspace);
262
+ await ActiveShellCommand.mkdir(path.dirname(cfg.output));
245
263
  yield ActiveShellCommand.zip(cfg.output);
246
264
  yield ActiveShellCommand.chdir(path.cwd());
247
265
  } else {
266
+ await fs.mkdir(path.dirname(cfg.output), { recursive: true });
248
267
  const [cmd, ...args] = ActiveShellCommand.zip(cfg.output);
249
268
  await ExecUtil.spawn(cmd, args, { cwd: cfg.workspace }).result;
250
269
  }
@@ -69,6 +69,7 @@ export abstract class BasePackCommand implements CliCommandShape {
69
69
  PackOperation.writeEntryScript,
70
70
  PackOperation.copyResources,
71
71
  PackOperation.writeManifest,
72
+ PackOperation.duplicateNodeModules,
72
73
  PackOperation.bundle,
73
74
  ];
74
75
  }