@travetto/pack 4.0.6 → 4.1.1

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 ArcSine Technologies
3
+ Copyright (c) 2020 ArcSine Technologies
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/pack",
3
- "version": "4.0.6",
3
+ "version": "4.1.1",
4
4
  "description": "Code packing utilities",
5
5
  "keywords": [
6
6
  "travetto",
@@ -25,16 +25,16 @@
25
25
  "directory": "module/pack"
26
26
  },
27
27
  "dependencies": {
28
- "@rollup/plugin-commonjs": "^25.0.7",
28
+ "@rollup/plugin-commonjs": "^26.0.1",
29
29
  "@rollup/plugin-json": "^6.1.0",
30
30
  "@rollup/plugin-node-resolve": "^15.2.3",
31
31
  "@rollup/plugin-terser": "^0.4.4",
32
- "@travetto/base": "^4.0.6",
33
- "@travetto/terminal": "^4.0.6",
34
- "rollup": "^4.12.1"
32
+ "@travetto/base": "^4.1.1",
33
+ "@travetto/terminal": "^4.1.1",
34
+ "rollup": "^4.18.0"
35
35
  },
36
36
  "peerDependencies": {
37
- "@travetto/cli": "^4.0.8"
37
+ "@travetto/cli": "^4.1.1"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "@travetto/cli": {
package/src/types.ts CHANGED
@@ -11,6 +11,7 @@ export type CommonPackConfig = {
11
11
  mainScripts?: boolean;
12
12
  module: string;
13
13
  envFile: string;
14
+ env?: string;
14
15
  manifestFile: string;
15
16
 
16
17
  // Bundle
@@ -20,6 +21,7 @@ export type CommonPackConfig = {
20
21
  minify: boolean;
21
22
  sourcemap: boolean;
22
23
  includeSources: boolean;
24
+ includeWorkspaceResources?: boolean;
23
25
  };
24
26
 
25
27
 
@@ -51,7 +53,7 @@ export type ShellCommandImpl = {
51
53
  chdirScript(): string[];
52
54
  callCommandWithAllArgs(cmd: string, ...args: string[]): string[];
53
55
  copy(src: string, dest: string): string[];
54
- copyRecursive(src: string, dest: string): string[];
56
+ copyRecursive(src: string, dest: string, inclusive?: boolean): string[];
55
57
  rmRecursive(dest: string): string[];
56
58
  mkdir(dest: string): string[];
57
59
  export(key: string, value: string): string[];
@@ -177,6 +177,27 @@ export class PackOperation {
177
177
  }
178
178
  }
179
179
 
180
+ /**
181
+ * Copy over repo /resources folder into workspace, will get packaged into final output
182
+ */
183
+ static async * copyMonoRepoResources(cfg: CommonPackConfig): AsyncIterable<string[]> {
184
+ if (!cfg.includeWorkspaceResources) {
185
+ return;
186
+ }
187
+
188
+ yield* PackOperation.title(cfg, cliTpl`${{ title: 'Copying over workspace resources' }}`);
189
+
190
+ const dest = path.resolve(cfg.workspace, 'workspace-resources');
191
+ const src = RuntimeContext.workspaceRelative('resources');
192
+
193
+ if (cfg.ejectFile) {
194
+ yield ActiveShellCommand.copyRecursive(src, dest, true);
195
+ } else {
196
+ await fs.mkdir(dest, { recursive: true });
197
+ await PackUtil.copyRecursive(src, dest, true);
198
+ }
199
+ }
200
+
180
201
  /**
181
202
  * Copy over /resources folder into workspace, will get packaged into final output
182
203
  */
@@ -187,7 +208,7 @@ export class PackOperation {
187
208
  dest: path.resolve(cfg.workspace, 'resources')
188
209
  };
189
210
 
190
- yield* PackOperation.title(cfg, cliTpl`${{ title: 'Copying over resources' }}`);
211
+ yield* PackOperation.title(cfg, cliTpl`${{ title: 'Copying over module resources' }}`);
191
212
 
192
213
  if (cfg.ejectFile) {
193
214
  if (resources.count) {
@@ -1,5 +1,6 @@
1
+ import util from 'node:util';
2
+
1
3
  import { path } from '@travetto/manifest';
2
- import { StyleUtil } from '@travetto/terminal';
3
4
 
4
5
  import { ShellCommandImpl } from '../../src/types';
5
6
 
@@ -25,13 +26,14 @@ export const ShellCommands: Record<'win32' | 'posix', ShellCommandImpl> = {
25
26
  )
26
27
  ],
27
28
  copy: (src, dest) => ['copy', src, dest],
28
- copyRecursive: (src, dest) => ['xcopy', '/y', '/h', '/s', path.toNative(src), path.toNative(dest)],
29
+ copyRecursive: (src, dest, inclusive) =>
30
+ ['xcopy', '/y', '/h', '/s', inclusive ? `${path.toNative(src)}\\*.*` : path.toNative(src), path.toNative(dest)],
29
31
  rmRecursive: (dest) => ['rmdir', '/Q', '/S', dest],
30
32
  mkdir: (dest) => ['md', dest],
31
33
  export: (key, value) => ['set', `${key}=${value}`],
32
34
  chdir: (dest) => ['cd', dest],
33
- comment: (message) => ['\nREM', StyleUtil.cleanText(message), '\n'],
34
- echo: (message) => ['echo', `"${escape(StyleUtil.cleanText(message))}"\n`],
35
+ comment: (message) => ['\nREM', util.stripVTControlCharacters(message), '\n'],
36
+ echo: (message) => ['echo', `"${escape(util.stripVTControlCharacters(message))}"\n`],
35
37
  zip: (outputFile) => ['powershell', 'Compress-Archive', '-Path', '.', '-DestinationPath', outputFile]
36
38
  },
37
39
  posix: {
@@ -45,13 +47,14 @@ export const ShellCommands: Record<'win32' | 'posix', ShellCommandImpl> = {
45
47
  ...(mode ? [['chmod', mode, file]] : [])
46
48
  ],
47
49
  copy: (src, dest) => ['cp', src, dest],
48
- copyRecursive: (src, dest) => ['cp', '-r', '-p', src, dest],
50
+ copyRecursive: (src, dest, inclusive) =>
51
+ ['cp', '-r', '-p', inclusive ? `${src}/*` : src, dest],
49
52
  rmRecursive: (dest) => ['rm', '-rf', dest],
50
53
  mkdir: (dest) => ['mkdir', '-p', dest],
51
54
  export: (key, value) => ['export', `${key}=${value}`],
52
55
  chdir: (dest) => ['cd', dest],
53
- comment: (message) => ['\n#', StyleUtil.cleanText(message), '\n'],
54
- echo: (message) => ['echo', `"${escape(StyleUtil.cleanText(message))}"\n`],
56
+ comment: (message) => ['\n#', util.stripVTControlCharacters(message), '\n'],
57
+ echo: (message) => ['echo', `"${escape(util.stripVTControlCharacters(message))}"\n`],
55
58
  zip: (outputFile) => ['zip', '-r', outputFile, '.']
56
59
  },
57
60
  };
@@ -22,9 +22,9 @@ export class PackUtil {
22
22
  * @param dest The folder to copy to
23
23
  * @param ignore Should errors be ignored
24
24
  */
25
- static async copyRecursive(src: string, dest: string, ignore = false): Promise<void> {
26
- const [cmd, ...args] = ActiveShellCommand.copyRecursive(src, dest);
27
- const res = await ExecUtil.getResult(spawn(cmd, args, { shell: false }), { catch: true });
25
+ static async copyRecursive(src: string, dest: string, inclusive: boolean = false, ignore = false): Promise<void> {
26
+ const [cmd, ...args] = ActiveShellCommand.copyRecursive(src, dest, inclusive);
27
+ const res = await ExecUtil.getResult(spawn(cmd, args, { shell: true }), { catch: true });
28
28
  if (res.code && !ignore) {
29
29
  throw new Error(`Failed to copy ${src} to ${dest}`);
30
30
  }
@@ -48,8 +48,8 @@ export class PackUtil {
48
48
 
49
49
  if (!(file === '-' || file === '/dev/stdout')) {
50
50
  await fs.mkdir(path.dirname(file), { recursive: true });
51
- await fs.truncate(file);
52
- stream = await fs.open(file, 'utf8');
51
+ await fs.writeFile(file, '', 'utf8');
52
+ stream = await fs.open(file, 'w', 0o755);
53
53
  }
54
54
 
55
55
  const write = (text: string): Promise<unknown> | unknown => stream ? stream.write(`${text}\n`) : process.stdout.write(`${text}\n`);
@@ -68,6 +68,9 @@ export abstract class BasePackCommand implements CliCommandShape {
68
68
  @CliFlag({ desc: 'Manifest File Name' })
69
69
  manifestFile = 'manifest.json';
70
70
 
71
+ @CliFlag({ desc: 'Include workspace resources', short: 'wr' })
72
+ includeWorkspaceResources: boolean = false;
73
+
71
74
  @Ignore()
72
75
  module: string;
73
76
 
@@ -84,6 +87,7 @@ export abstract class BasePackCommand implements CliCommandShape {
84
87
  PackOperation.writeEnv,
85
88
  PackOperation.writePackageJson,
86
89
  PackOperation.writeEntryScript,
90
+ PackOperation.copyMonoRepoResources,
87
91
  PackOperation.copyResources,
88
92
  PackOperation.writeManifest,
89
93
  PackOperation.bundle,