@travetto/pack 5.0.0-rc.8 → 5.0.0
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 +4 -0
- package/package.json +5 -5
- package/src/config-util.ts +19 -1
- package/src/types.ts +2 -0
- package/support/bin/docker-operation.ts +7 -2
- package/support/bin/operation.ts +2 -1
- package/support/bin/util.ts +1 -1
- package/support/pack.base.ts +3 -0
- package/support/rollup/build.ts +1 -0
- package/support/rollup/config.ts +11 -3
package/README.md
CHANGED
|
@@ -43,6 +43,7 @@ Options:
|
|
|
43
43
|
--env-file <string> Env Flag File Name (default: ".env")
|
|
44
44
|
--manifest-file <string> Manifest File Name (default: "manifest.json")
|
|
45
45
|
-wr, --include-workspace-resources Include workspace resources (default: false)
|
|
46
|
+
-np, --npm-package <string> External NPM Packages (default: [])
|
|
46
47
|
-m, --module <module> Module to run for
|
|
47
48
|
-h, --help display help for command
|
|
48
49
|
```
|
|
@@ -108,6 +109,7 @@ Options:
|
|
|
108
109
|
--env-file <string> Env Flag File Name (default: ".env")
|
|
109
110
|
--manifest-file <string> Manifest File Name (default: "manifest.json")
|
|
110
111
|
-wr, --include-workspace-resources Include workspace resources (default: false)
|
|
112
|
+
-np, --npm-package <string> External NPM Packages (default: [])
|
|
111
113
|
-m, --module <module> Module to run for
|
|
112
114
|
-h, --help display help for command
|
|
113
115
|
```
|
|
@@ -136,6 +138,7 @@ Options:
|
|
|
136
138
|
--env-file <string> Env Flag File Name (default: ".env")
|
|
137
139
|
--manifest-file <string> Manifest File Name (default: "manifest.json")
|
|
138
140
|
-wr, --include-workspace-resources Include workspace resources (default: false)
|
|
141
|
+
-np, --npm-package <string> External NPM Packages (default: [])
|
|
139
142
|
-df, --docker-factory <string> Docker Factory source (default: "@travetto/pack/support/pack.dockerfile")
|
|
140
143
|
-di, --docker-image <string> Docker Image to extend (default: "node:22-alpine")
|
|
141
144
|
-dn, --docker-name <string> Docker Image Name (default: "travetto_pack")
|
|
@@ -259,6 +262,7 @@ echo "RUN addgroup -g 2000 app && adduser -D -G app -u 2000 app" >> $DIST/Docker
|
|
|
259
262
|
echo "RUN mkdir /app && chown app:app /app" >> $DIST/Dockerfile
|
|
260
263
|
echo "COPY --chown=\"app:app\" . /app" >> $DIST/Dockerfile
|
|
261
264
|
echo "ENV NODE_OPTIONS=\"\"" >> $DIST/Dockerfile
|
|
265
|
+
echo "" >> $DIST/Dockerfile
|
|
262
266
|
echo "USER app" >> $DIST/Dockerfile
|
|
263
267
|
echo "WORKDIR /app" >> $DIST/Dockerfile
|
|
264
268
|
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": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Code packing utilities",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"travetto",
|
|
@@ -29,12 +29,12 @@
|
|
|
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/runtime": "^5.0.0
|
|
33
|
-
"@travetto/terminal": "^5.0.0
|
|
34
|
-
"rollup": "^4.
|
|
32
|
+
"@travetto/runtime": "^5.0.0",
|
|
33
|
+
"@travetto/terminal": "^5.0.0",
|
|
34
|
+
"rollup": "^4.20.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@travetto/cli": "^5.0.0
|
|
37
|
+
"@travetto/cli": "^5.0.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependenciesMeta": {
|
|
40
40
|
"@travetto/cli": {
|
package/src/config-util.ts
CHANGED
|
@@ -29,6 +29,23 @@ export class PackConfigUtil {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Install docker pages in either apk or apt environments
|
|
34
|
+
*/
|
|
35
|
+
static dockerNodePackageInstall(cfg: DockerPackConfig): string {
|
|
36
|
+
const out: string[] = [];
|
|
37
|
+
for (const item of cfg.externalDependencies ?? []) {
|
|
38
|
+
out.push(item.endsWith(':from-source') ?
|
|
39
|
+
`RUN npm_config_build_from_source=true npm install ${item.split(':')[0]} --build-from-source` :
|
|
40
|
+
`RUN npm install ${item}`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (out.length) {
|
|
44
|
+
out.unshift(`WORKDIR ${cfg.dockerRuntime.folder}`);
|
|
45
|
+
}
|
|
46
|
+
return out.join('\n');
|
|
47
|
+
}
|
|
48
|
+
|
|
32
49
|
/**
|
|
33
50
|
* Setup docker ports
|
|
34
51
|
*/
|
|
@@ -74,7 +91,7 @@ export class PackConfigUtil {
|
|
|
74
91
|
}
|
|
75
92
|
|
|
76
93
|
/**
|
|
77
|
-
* Docker app files copied
|
|
94
|
+
* Docker app files copied with proper permissions
|
|
78
95
|
*/
|
|
79
96
|
static dockerAppFiles(cfg: DockerPackConfig): string {
|
|
80
97
|
const { user, group, folder } = cfg.dockerRuntime;
|
|
@@ -113,6 +130,7 @@ export class PackConfigUtil {
|
|
|
113
130
|
return [
|
|
114
131
|
this.dockerInit(cfg),
|
|
115
132
|
this.dockerWorkspace(cfg),
|
|
133
|
+
this.dockerNodePackageInstall(cfg),
|
|
116
134
|
this.dockerEntrypoint(cfg)
|
|
117
135
|
].join('\n');
|
|
118
136
|
}
|
package/src/types.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type CommonPackConfig = {
|
|
|
19
19
|
rollupConfiguration: string;
|
|
20
20
|
entryPoint: string;
|
|
21
21
|
entryArguments: string[];
|
|
22
|
+
externalDependencies: string[];
|
|
22
23
|
minify: boolean;
|
|
23
24
|
sourcemap: boolean;
|
|
24
25
|
includeSources: boolean;
|
|
@@ -72,5 +73,6 @@ export type CoreRollupConfig = {
|
|
|
72
73
|
entry: string;
|
|
73
74
|
files: string[];
|
|
74
75
|
ignore: Set<string>;
|
|
76
|
+
external: string[];
|
|
75
77
|
minify: Parameters<typeof terser>[0];
|
|
76
78
|
};
|
|
@@ -22,8 +22,13 @@ export class DockerPackOperation {
|
|
|
22
22
|
// Read os before writing
|
|
23
23
|
cfg.dockerRuntime.os = await PackUtil.runCommand(
|
|
24
24
|
['docker', 'run', '--entrypoint', '/bin/sh', cfg.dockerImage, '-c', 'cat /etc/*release*']
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
).then(out => {
|
|
26
|
+
const found = out.match(/\b(?:debian|alpine|centos)\b/i)?.[0].toLowerCase();
|
|
27
|
+
switch (found) {
|
|
28
|
+
case 'debian': case 'alpine': case 'centos': return found;
|
|
29
|
+
default: return 'unknown';
|
|
30
|
+
}
|
|
31
|
+
});
|
|
27
32
|
yield* PackOperation.title(cfg, cliTpl`${{ title: 'Detected Image OS' }} ${{ param: cfg.dockerImage }} as ${{ param: cfg.dockerRuntime.os }}`);
|
|
28
33
|
}
|
|
29
34
|
|
package/support/bin/operation.ts
CHANGED
|
@@ -67,7 +67,8 @@ export class PackOperation {
|
|
|
67
67
|
['BUNDLE_SOURCES', cfg.includeSources],
|
|
68
68
|
['BUNDLE_OUTPUT', cfg.buildDir],
|
|
69
69
|
['BUNDLE_FORMAT', Runtime.workspace.type],
|
|
70
|
-
['BUNDLE_ENV_FILE', cfg.envFile]
|
|
70
|
+
['BUNDLE_ENV_FILE', cfg.envFile],
|
|
71
|
+
['BUNDLE_EXTERNAL', cfg.externalDependencies.join(',')]
|
|
71
72
|
] as const)
|
|
72
73
|
.filter(x => x[1] === false || x[1])
|
|
73
74
|
.map(x => [x[0], `${x[1]}`])
|
package/support/bin/util.ts
CHANGED
package/support/pack.base.ts
CHANGED
|
@@ -71,6 +71,9 @@ export abstract class BasePackCommand implements CliCommandShape {
|
|
|
71
71
|
@CliFlag({ desc: 'Include workspace resources', short: 'wr' })
|
|
72
72
|
includeWorkspaceResources: boolean = false;
|
|
73
73
|
|
|
74
|
+
@CliFlag({ desc: 'External NPM Packages', short: 'np', name: 'npm-package', envVars: ['PACK_EXTERNAL_PACKAGES'] })
|
|
75
|
+
externalDependencies: string[] = [];
|
|
76
|
+
|
|
74
77
|
@Ignore()
|
|
75
78
|
module: string;
|
|
76
79
|
|
package/support/rollup/build.ts
CHANGED
package/support/rollup/config.ts
CHANGED
|
@@ -21,9 +21,16 @@ function getFilesFromModule(m: ManifestModule): string[] {
|
|
|
21
21
|
.map(([f]) => ManifestModuleUtil.withOutputExtension(path.resolve(m.outputFolder, f)));
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
function getFormat(value: string = 'commonjs'): NodeModuleType {
|
|
25
|
+
switch (value) {
|
|
26
|
+
case 'module':
|
|
27
|
+
case 'commonjs': return value;
|
|
28
|
+
default: return 'commonjs';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
export function getOutput(): OutputOptions {
|
|
25
|
-
|
|
26
|
-
const format = (process.env.BUNDLE_FORMAT ?? 'commonjs') as NodeModuleType;
|
|
33
|
+
const format = getFormat(process.env.BUNDLE_FORMAT);
|
|
27
34
|
const dir = process.env.BUNDLE_OUTPUT!;
|
|
28
35
|
const mainFile = process.env.BUNDLE_MAIN_FILE!;
|
|
29
36
|
return {
|
|
@@ -79,9 +86,10 @@ export function getCoreConfig(): CoreRollupConfig {
|
|
|
79
86
|
const ignoreFiles = ignoreModules.flatMap(getFilesFromModule);
|
|
80
87
|
const minify = getMinifyConfig();
|
|
81
88
|
const envFile = new EnvProp('BUNDLE_ENV_FILE').val;
|
|
89
|
+
const external = new EnvProp('BUNDLE_EXTERNAL').list ?? [];
|
|
82
90
|
|
|
83
91
|
return {
|
|
84
|
-
output, entry, files, envFile, minify,
|
|
92
|
+
output, entry, files, envFile, minify, external,
|
|
85
93
|
ignore: new Set([...ignoreModules.map(x => x.name), ...ignoreFiles]),
|
|
86
94
|
};
|
|
87
95
|
}
|