@travetto/pack 8.0.0-alpha.2 → 8.0.0-alpha.20
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 +31 -13
- package/package.json +7 -7
- package/support/cli.pack.ts +5 -2
- package/support/cli.pack_docker.ts +6 -3
- package/support/cli.pack_zip.ts +5 -2
- package/support/pack.base.ts +12 -13
- package/support/rollup/rollup-travetto-import.ts +8 -9
- package/support/rollup/rollup-travetto-sourcemaps.ts +6 -3
package/README.md
CHANGED
|
@@ -22,12 +22,18 @@ There are three primary cli commands for packing your code:
|
|
|
22
22
|
|
|
23
23
|
## CLI - pack
|
|
24
24
|
|
|
25
|
-
**Terminal:
|
|
25
|
+
**Terminal: Help for pack**
|
|
26
26
|
```bash
|
|
27
27
|
$ trv pack --help
|
|
28
28
|
|
|
29
29
|
Usage: pack [options] [args...:string]
|
|
30
30
|
|
|
31
|
+
Build a standard module package artifact.
|
|
32
|
+
|
|
33
|
+
This base command produces the default packaged output and serves as the
|
|
34
|
+
common entry point for module packaging workflows.
|
|
35
|
+
Example Usage:
|
|
36
|
+
|
|
31
37
|
Options:
|
|
32
38
|
-b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
|
|
33
39
|
--clean, --no-clean Clean workspace (default: true)
|
|
@@ -45,7 +51,7 @@ Options:
|
|
|
45
51
|
-wr, --include-workspace-resources Include workspace resources (default: false)
|
|
46
52
|
-np, --npm-package <string> External NPM Packages (default: [])
|
|
47
53
|
-m, --module <module> Module to run for
|
|
48
|
-
|
|
54
|
+
--help display help for command
|
|
49
55
|
```
|
|
50
56
|
|
|
51
57
|
This command line operation will compile your project, and produce a ready to use workspace as a deliverable. Additionally, you can pass in a file to the `eject-file` flag that will allow for a script to be produced (base on the host operating system).
|
|
@@ -88,12 +94,18 @@ Every [Pack](https://github.com/travetto/travetto/tree/main/module/pack#readme "
|
|
|
88
94
|
## CLI - pack:zip
|
|
89
95
|
This command is nearly identical to the standard `pack` operation, except for the `output` flag. In this scenario, the `output` flag determines the location and name of the final zip file.
|
|
90
96
|
|
|
91
|
-
**Terminal:
|
|
97
|
+
**Terminal: Help for pack:zip**
|
|
92
98
|
```bash
|
|
93
99
|
$ trv pack:zip --help
|
|
94
100
|
|
|
95
101
|
Usage: pack:zip [options] [args...:string]
|
|
96
102
|
|
|
103
|
+
Build a deployable zip artifact using the standard pack pipeline.
|
|
104
|
+
|
|
105
|
+
This command runs base packing operations and then compresses the generated
|
|
106
|
+
output into a single archive file.
|
|
107
|
+
Example Usage:
|
|
108
|
+
|
|
97
109
|
Options:
|
|
98
110
|
-b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
|
|
99
111
|
--clean, --no-clean Clean workspace (default: true)
|
|
@@ -111,18 +123,24 @@ Options:
|
|
|
111
123
|
-wr, --include-workspace-resources Include workspace resources (default: false)
|
|
112
124
|
-np, --npm-package <string> External NPM Packages (default: [])
|
|
113
125
|
-m, --module <module> Module to run for
|
|
114
|
-
|
|
126
|
+
--help display help for command
|
|
115
127
|
```
|
|
116
128
|
|
|
117
129
|
## CLI - pack:docker
|
|
118
130
|
This command starts off identical to the standard `pack` operation, but it contains a few additional flags, and ultimately a few additional operations to support creating of the final [docker](https://www.docker.com/community-edition) image.
|
|
119
131
|
|
|
120
|
-
**Terminal:
|
|
132
|
+
**Terminal: Help for pack:docker**
|
|
121
133
|
```bash
|
|
122
134
|
$ trv pack:docker --help
|
|
123
135
|
|
|
124
136
|
Usage: pack:docker [options] [args...:string]
|
|
125
137
|
|
|
138
|
+
Build container-ready artifacts and optionally publish Docker images.
|
|
139
|
+
|
|
140
|
+
Extends the core pack pipeline with Dockerfile generation and image build/
|
|
141
|
+
push operations, including runtime user and registry customization.
|
|
142
|
+
Example Usage:
|
|
143
|
+
|
|
126
144
|
Options:
|
|
127
145
|
-b, --buildDir <string> Workspace for building (default: "/tmp/<temp-folder>")
|
|
128
146
|
--clean, --no-clean Clean workspace (default: true)
|
|
@@ -141,7 +159,7 @@ Options:
|
|
|
141
159
|
-np, --npm-package <string> External NPM Packages (default: [])
|
|
142
160
|
-m, --module <module> Module to run for
|
|
143
161
|
-df, --docker-factory <string> Docker Factory source (default: "@travetto/pack/support/pack.dockerfile.ts")
|
|
144
|
-
-di, --docker-image <string> Docker Image to extend (default: "node:
|
|
162
|
+
-di, --docker-image <string> Docker Image to extend (default: "node:26-alpine")
|
|
145
163
|
-dn, --docker-name <string> Docker Image Name (default: "<module>")
|
|
146
164
|
-ru, --runtime-user <string> Docker Runtime user
|
|
147
165
|
-rp, --runtime-package <string> Docker Runtime Packages (default: [])
|
|
@@ -151,7 +169,7 @@ Options:
|
|
|
151
169
|
-dx, --docker-push Docker Push Tags (default: false)
|
|
152
170
|
-db, --docker-build-platform <string> Docker Build Platform
|
|
153
171
|
-dr, --docker-registry <string> Docker Registry
|
|
154
|
-
|
|
172
|
+
--help display help for command
|
|
155
173
|
```
|
|
156
174
|
|
|
157
175
|
The additional flags provided are allow for specifying the base image, the final docker image name (and tags), and which registry to push to (if any). Additionally, there are flags for exposing which ports the image should expect to open as well. When using the `--eject-file` flag, the output script will produce the entire Dockerfile output inline, so that it can be easily modified as needed.
|
|
@@ -244,21 +262,21 @@ cd $TRV_OUT
|
|
|
244
262
|
node $REPO_ROOT/node_modules/.bin/rollup -c $TRV_OUT/node_modules/@travetto/pack/support/rollup/build.js
|
|
245
263
|
cd $ROOT
|
|
246
264
|
|
|
247
|
-
# Pulling Docker Base Image node:
|
|
265
|
+
# Pulling Docker Base Image node:26-alpine
|
|
248
266
|
|
|
249
|
-
echo "Pulling Docker Base Image node:
|
|
267
|
+
echo "Pulling Docker Base Image node:26-alpine"
|
|
250
268
|
|
|
251
|
-
docker pull node:
|
|
269
|
+
docker pull node:26-alpine
|
|
252
270
|
|
|
253
|
-
# Detected Image OS node:
|
|
271
|
+
# Detected Image OS node:26-alpine as alpine
|
|
254
272
|
|
|
255
|
-
echo "Detected Image OS node:
|
|
273
|
+
echo "Detected Image OS node:26-alpine as alpine"
|
|
256
274
|
|
|
257
275
|
# Generating Docker File $DIST/Dockerfile @travetto/pack/support/pack.dockerfile.ts
|
|
258
276
|
|
|
259
277
|
echo "Generating Docker File $DIST/Dockerfile @travetto/pack/support/pack.dockerfile.ts"
|
|
260
278
|
|
|
261
|
-
echo "FROM node:
|
|
279
|
+
echo "FROM node:26-alpine" > $DIST/Dockerfile
|
|
262
280
|
echo "RUN addgroup -g 2000 app && adduser -D -G app -u 2000 app" >> $DIST/Dockerfile
|
|
263
281
|
echo "RUN mkdir /app && chown app:app /app" >> $DIST/Dockerfile
|
|
264
282
|
echo "COPY --chown=\"app:app\" . /app" >> $DIST/Dockerfile
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/pack",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Code packing utilities",
|
|
6
6
|
"keywords": [
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
"directory": "module/pack"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@rollup/plugin-commonjs": "^29.0.
|
|
29
|
+
"@rollup/plugin-commonjs": "^29.0.3",
|
|
30
30
|
"@rollup/plugin-json": "^6.1.0",
|
|
31
31
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
32
|
-
"@rollup/plugin-terser": "^0.
|
|
33
|
-
"@travetto/runtime": "^8.0.0-alpha.
|
|
34
|
-
"@travetto/terminal": "^8.0.0-alpha.
|
|
35
|
-
"rollup": "^4.
|
|
32
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
33
|
+
"@travetto/runtime": "^8.0.0-alpha.17",
|
|
34
|
+
"@travetto/terminal": "^8.0.0-alpha.17",
|
|
35
|
+
"rollup": "^4.61.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
38
|
+
"@travetto/cli": "^8.0.0-alpha.23"
|
|
39
39
|
},
|
|
40
40
|
"peerDependenciesMeta": {
|
|
41
41
|
"@travetto/cli": {
|
package/support/cli.pack.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { CliCommand } from '@travetto/cli';
|
|
2
2
|
|
|
3
|
-
import { BasePackCommand } from './pack.base';
|
|
3
|
+
import { BasePackCommand } from './pack.base.ts';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Build a standard module package artifact.
|
|
7
|
+
*
|
|
8
|
+
* This base command produces the default packaged output and serves as the
|
|
9
|
+
* common entry point for module packaging workflows.
|
|
7
10
|
*/
|
|
8
11
|
@CliCommand()
|
|
9
12
|
export class PackCommand extends BasePackCommand { }
|
|
@@ -5,7 +5,7 @@ import { CliCommand, CliFlag, CliUtil } from '@travetto/cli';
|
|
|
5
5
|
import { Ignore, Max, Min, Required } from '@travetto/schema';
|
|
6
6
|
|
|
7
7
|
import { DockerPackOperation } from './bin/docker-operation.ts';
|
|
8
|
-
import { BasePackCommand, type PackOperationShape } from './pack.base';
|
|
8
|
+
import { BasePackCommand, type PackOperationShape } from './pack.base.ts';
|
|
9
9
|
import type { DockerPackConfig } from '../src/types.ts';
|
|
10
10
|
|
|
11
11
|
const NODE_MAJOR = process.version.match(/\d+/)?.[0] ?? '22';
|
|
@@ -13,7 +13,10 @@ const asNumber = (input?: string): number | undefined => (!input || isNaN(+input
|
|
|
13
13
|
const asString = (input?: string): string | undefined => (input && asNumber(input)) ? input : undefined;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Build container-ready artifacts and optionally publish Docker images.
|
|
17
|
+
*
|
|
18
|
+
* Extends the core pack pipeline with Dockerfile generation and image build/
|
|
19
|
+
* push operations, including runtime user and registry customization.
|
|
17
20
|
*/
|
|
18
21
|
@CliCommand()
|
|
19
22
|
export class PackDockerCommand extends BasePackCommand {
|
|
@@ -24,7 +27,7 @@ export class PackDockerCommand extends BasePackCommand {
|
|
|
24
27
|
@CliFlag({ short: 'di', envVars: ['PACK_DOCKER_IMAGE'] })
|
|
25
28
|
dockerImage = `node:${NODE_MAJOR}-alpine`;
|
|
26
29
|
/** Docker Image Name */
|
|
27
|
-
@CliFlag({ short: 'dn', envVars: ['
|
|
30
|
+
@CliFlag({ short: 'dn', envVars: ['PACK_DOCKER_NAME'] })
|
|
28
31
|
@Required(false)
|
|
29
32
|
dockerName: string;
|
|
30
33
|
/** Docker Runtime user */
|
package/support/cli.pack_zip.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { CliCommand, CliUtil } from '@travetto/cli';
|
|
2
2
|
|
|
3
3
|
import { PackOperation } from './bin/operation.ts';
|
|
4
|
-
import { BasePackCommand, type PackOperationShape } from './pack.base';
|
|
4
|
+
import { BasePackCommand, type PackOperationShape } from './pack.base.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Build a deployable zip artifact using the standard pack pipeline.
|
|
8
|
+
*
|
|
9
|
+
* This command runs base packing operations and then compresses the generated
|
|
10
|
+
* output into a single archive file.
|
|
8
11
|
*/
|
|
9
12
|
@CliCommand()
|
|
10
13
|
export class PackZipCommand extends BasePackCommand {
|
package/support/pack.base.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type CliCommandShape, CliFlag, CliModuleFlag, CliParseUtil, cliTpl } fr
|
|
|
5
5
|
import { TimeUtil, Runtime, RuntimeIndex } from '@travetto/runtime';
|
|
6
6
|
import { Terminal } from '@travetto/terminal';
|
|
7
7
|
import { Ignore, Method, Required, Schema } from '@travetto/schema';
|
|
8
|
-
import { PackageUtil } from '@travetto/manifest';
|
|
8
|
+
import { PackageUtil, type IndexedModule } from '@travetto/manifest';
|
|
9
9
|
|
|
10
10
|
import { PackOperation } from './bin/operation.ts';
|
|
11
11
|
import { PackUtil } from './bin/util.ts';
|
|
@@ -114,22 +114,21 @@ export abstract class BasePackCommand implements CliCommandShape {
|
|
|
114
114
|
*/
|
|
115
115
|
async * runOperations(): AsyncIterable<string> {
|
|
116
116
|
for (const operation of this.getOperations()) {
|
|
117
|
-
for await (const
|
|
118
|
-
yield
|
|
117
|
+
for await (const message of operation(this)) {
|
|
118
|
+
yield message.join(' ');
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
* Get all
|
|
124
|
+
* Get all external dependencies
|
|
125
125
|
*/
|
|
126
|
-
|
|
126
|
+
getModuleExternalDependencies(): string[] {
|
|
127
127
|
return [...RuntimeIndex.getModuleList('all')]
|
|
128
128
|
.map(name => RuntimeIndex.getModule(name))
|
|
129
|
-
.filter(module => !!module)
|
|
130
|
-
.filter(module => module.production)
|
|
129
|
+
.filter((module): module is IndexedModule => !!module?.production)
|
|
131
130
|
.map(module => PackageUtil.readPackage(module?.sourcePath))
|
|
132
|
-
.map(pkg => pkg?.travetto?.build?.
|
|
131
|
+
.map(pkg => pkg?.travetto?.build?.externalDependencies ?? [])
|
|
133
132
|
.flat();
|
|
134
133
|
}
|
|
135
134
|
|
|
@@ -147,8 +146,8 @@ export abstract class BasePackCommand implements CliCommandShape {
|
|
|
147
146
|
this.mainName ??= path.basename(this.module);
|
|
148
147
|
this.mainFile = `${this.mainName}.js`;
|
|
149
148
|
|
|
150
|
-
// Collect
|
|
151
|
-
const dependencies = this.
|
|
149
|
+
// Collect unmanaged dependencies
|
|
150
|
+
const dependencies = this.getModuleExternalDependencies();
|
|
152
151
|
this.externalDependencies = [...this.externalDependencies, ...dependencies];
|
|
153
152
|
|
|
154
153
|
const stream = this.runOperations();
|
|
@@ -162,11 +161,11 @@ export abstract class BasePackCommand implements CliCommandShape {
|
|
|
162
161
|
|
|
163
162
|
await term.streamLines(stream);
|
|
164
163
|
|
|
165
|
-
let
|
|
164
|
+
let message = cliTpl`${{ success: 'Success' }} (${{ identifier: TimeUtil.asClock(Date.now() - start) }}) ${{ subtitle: 'module' }}=${{ param: this.module }}`;
|
|
166
165
|
if (this.output) {
|
|
167
|
-
|
|
166
|
+
message = cliTpl`${message} ${{ subtitle: 'output' }}=${{ path: this.output }}`;
|
|
168
167
|
}
|
|
169
|
-
await term.writer.writeLine(
|
|
168
|
+
await term.writer.writeLine(message).commit();
|
|
170
169
|
}
|
|
171
170
|
}
|
|
172
171
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AstNode, Plugin } from 'rollup';
|
|
2
|
+
// @ts-expect-error - This module lacks types
|
|
2
3
|
import { walk } from 'estree-walker';
|
|
3
4
|
import magicString from 'magic-string';
|
|
4
5
|
|
|
@@ -33,16 +34,14 @@ export function travettoImportPlugin(config: CoreRollupConfig): Plugin {
|
|
|
33
34
|
let ms: magicString | undefined;
|
|
34
35
|
|
|
35
36
|
walk(parsed, {
|
|
36
|
-
enter: (node) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!/["']/.test(code.substring(impNode.start, impNode.end))) {
|
|
41
|
-
(ms ??= new magicString(code)).overwrite(impNode.start, impNode.start + 6, GLOBAL_IMPORT);
|
|
37
|
+
enter: (node: TNode) => {
|
|
38
|
+
if (node.type === 'ImportExpression' && node.source?.type !== 'Literal') {
|
|
39
|
+
if (!/["']/.test(code.substring(node.start, node.end))) {
|
|
40
|
+
(ms ??= new magicString(code)).overwrite(node.start, node.start + 6, GLOBAL_IMPORT);
|
|
42
41
|
}
|
|
43
|
-
} else if (
|
|
44
|
-
if (!/["']/.test(code.substring(
|
|
45
|
-
(ms ??= new magicString(code)).overwrite(
|
|
42
|
+
} else if (node.type === 'CallExpression' && node.callee?.type === 'Identifier' && node.callee.name === 'require') {
|
|
43
|
+
if (!/["']/.test(code.substring(node.start, node.end))) {
|
|
44
|
+
(ms ??= new magicString(code)).overwrite(node.start, node.start + 7, GLOBAL_IMPORT);
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
}
|
|
@@ -18,7 +18,7 @@ export function travettoSourcemaps(config: CoreRollupConfig): Plugin {
|
|
|
18
18
|
return {
|
|
19
19
|
name: 'travetto-source-maps',
|
|
20
20
|
async load(this: PluginContext, id: string): Promise<LoadResult> {
|
|
21
|
-
if (!id.endsWith('.js')) {
|
|
21
|
+
if (!id.endsWith('.js') || id.endsWith('@travetto/runtime/support/patch.js')) {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
24
|
try {
|
|
@@ -30,8 +30,11 @@ export function travettoSourcemaps(config: CoreRollupConfig): Plugin {
|
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
const loader = new FileLoader([path.dirname(id)]);
|
|
33
|
-
const map = await loader.
|
|
34
|
-
.then(
|
|
33
|
+
const map = await loader.readUTF8(mapPath)
|
|
34
|
+
.then(value => value.startsWith('{') ?
|
|
35
|
+
JSONUtil.fromUTF8<SourceMapInput>(value) :
|
|
36
|
+
JSONUtil.fromBase64<SourceMapInput>(value)
|
|
37
|
+
);
|
|
35
38
|
return { code, map };
|
|
36
39
|
}
|
|
37
40
|
return { code, map: null };
|