@forge/bundler 4.21.1-next.9 → 4.22.0-next.16
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/CHANGELOG.md +67 -0
- package/out/dependencies.d.ts +6 -0
- package/out/dependencies.d.ts.map +1 -0
- package/out/dependencies.js +55 -0
- package/out/runtime.d.ts +3 -9
- package/out/runtime.d.ts.map +1 -1
- package/out/runtime.js +73 -8
- package/out/types.d.ts +3 -2
- package/out/types.d.ts.map +1 -1
- package/out/typescript.d.ts +16 -0
- package/out/typescript.d.ts.map +1 -0
- package/out/typescript.js +110 -0
- package/package.json +11 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,72 @@
|
|
|
1
1
|
# @forge/bundler
|
|
2
2
|
|
|
3
|
+
## 4.22.0-next.16
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4b083be: Option to bundle applications using TypeScript
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [4b083be]
|
|
12
|
+
- @forge/manifest@8.9.0-next.8
|
|
13
|
+
- @forge/cli-shared@6.8.0-next.15
|
|
14
|
+
- @forge/lint@5.7.3-next.16
|
|
15
|
+
|
|
16
|
+
## 4.21.1-next.15
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [7a83fd9]
|
|
21
|
+
- @forge/cli-shared@6.8.0-next.14
|
|
22
|
+
- @forge/lint@5.7.3-next.15
|
|
23
|
+
|
|
24
|
+
## 4.21.1-next.14
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- c57e34a: Fix bundling when handlers are defined in subdirectories
|
|
29
|
+
- Updated dependencies [c57e34a]
|
|
30
|
+
- @forge/cli-shared@6.8.0-next.13
|
|
31
|
+
- @forge/lint@5.7.3-next.14
|
|
32
|
+
|
|
33
|
+
## 4.21.1-next.13
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [7243788]
|
|
38
|
+
- @forge/cli-shared@6.8.0-next.12
|
|
39
|
+
- @forge/manifest@8.9.0-next.7
|
|
40
|
+
- @forge/lint@5.7.3-next.13
|
|
41
|
+
|
|
42
|
+
## 4.21.1-next.12
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- 336f74f: Support serving i18n resources while using `forge tunnel`
|
|
47
|
+
- Updated dependencies [04ab98e]
|
|
48
|
+
- Updated dependencies [336f74f]
|
|
49
|
+
- @forge/api@5.2.0-next.0
|
|
50
|
+
- @forge/cli-shared@6.8.0-next.11
|
|
51
|
+
- @forge/i18n@0.0.5-next.0
|
|
52
|
+
- @forge/lint@5.7.3-next.12
|
|
53
|
+
- @forge/manifest@8.9.0-next.6
|
|
54
|
+
|
|
55
|
+
## 4.21.1-next.11
|
|
56
|
+
|
|
57
|
+
### Patch Changes
|
|
58
|
+
|
|
59
|
+
- @forge/lint@5.7.3-next.11
|
|
60
|
+
|
|
61
|
+
## 4.21.1-next.10
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- Updated dependencies [de0bf46]
|
|
66
|
+
- @forge/manifest@8.9.0-next.5
|
|
67
|
+
- @forge/cli-shared@6.8.0-next.10
|
|
68
|
+
- @forge/lint@5.7.3-next.10
|
|
69
|
+
|
|
3
70
|
## 4.21.1-next.9
|
|
4
71
|
|
|
5
72
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependencies.d.ts","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":"AAwDA,aAAK,eAAe,GAAG;IACrB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAaF,wBAAsB,0BAA0B,CAC9C,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.copyProductionDependencies = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const common_1 = require("./common");
|
|
10
|
+
async function readPackageJSON(directory) {
|
|
11
|
+
try {
|
|
12
|
+
const packageJson = await (0, promises_1.readFile)(path_1.default.join(directory, 'package.json'), 'utf8');
|
|
13
|
+
return JSON.parse(packageJson);
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function dependencyDir(moduleDir, dependency) {
|
|
20
|
+
for (let source = moduleDir; source !== path_1.default.dirname(source); source = path_1.default.dirname(source)) {
|
|
21
|
+
const candidate = path_1.default.join(source, common_1.NODE_MODULES_DIR, dependency);
|
|
22
|
+
if ((0, fs_1.existsSync)(candidate)) {
|
|
23
|
+
return candidate;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function transplantDir(source, destination, directory) {
|
|
29
|
+
const relative = path_1.default.relative(source, directory);
|
|
30
|
+
return path_1.default.join(destination, relative);
|
|
31
|
+
}
|
|
32
|
+
async function copyProductionDependencies(moduleDir, target, options) {
|
|
33
|
+
const packageDef = await readPackageJSON(moduleDir);
|
|
34
|
+
if (!packageDef) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const exclude = options?.exclude ?? [];
|
|
38
|
+
for (const dependency of Object.keys(packageDef.dependencies ?? {})) {
|
|
39
|
+
if (exclude.includes(dependency)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const source = await dependencyDir(moduleDir, dependency);
|
|
43
|
+
if (source) {
|
|
44
|
+
const destination = transplantDir(moduleDir, target, source);
|
|
45
|
+
if ((0, fs_1.existsSync)(destination)) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
await (0, fs_extra_1.copy)(source, destination, {
|
|
49
|
+
filter: (src) => path_1.default.basename(src) !== common_1.NODE_MODULES_DIR
|
|
50
|
+
});
|
|
51
|
+
await copyProductionDependencies(source, destination, options);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.copyProductionDependencies = copyProductionDependencies;
|
package/out/runtime.d.ts
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
import { ConfigReader, StatsigReader } from '@forge/cli-shared';
|
|
2
|
-
import { BundleLogger, BundlerArgs } from './types';
|
|
2
|
+
import { BundleLogger, Bundler, BundlerArgs } from './types';
|
|
3
3
|
import { ConfigWithOutput, WebpackBundler } from './webpack';
|
|
4
4
|
import { WrapperProvider } from './wrapper-provider';
|
|
5
5
|
export declare class SandboxBundler extends WebpackBundler {
|
|
6
6
|
constructor(logger: BundleLogger);
|
|
7
7
|
getConfig(args: BundlerArgs): Promise<ConfigWithOutput>;
|
|
8
8
|
}
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
private readonly statsigReader;
|
|
12
|
-
constructor(logger: BundleLogger, wrapperProvider: WrapperProvider, statsigReader: StatsigReader);
|
|
13
|
-
getConfig(args: BundlerArgs): Promise<ConfigWithOutput>;
|
|
14
|
-
}
|
|
15
|
-
export declare function getNodeBundler(logger: BundleLogger, wrapperProvider: WrapperProvider, configReader: ConfigReader, statsigReader: StatsigReader): NodeBundler;
|
|
16
|
-
export {};
|
|
9
|
+
export declare function userCodePath(entryKey: string): string;
|
|
10
|
+
export declare function getNodeBundler(logger: BundleLogger, wrapperProvider: WrapperProvider, configReader: ConfigReader, statsigReader: StatsigReader): Bundler;
|
|
17
11
|
//# sourceMappingURL=runtime.d.ts.map
|
package/out/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,YAAY,EAGZ,aAAa,EAEd,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACL,YAAY,EACZ,OAAO,EACP,WAAW,EAMZ,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAiB,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGpE,qBAAa,cAAe,SAAQ,cAAc;gBACpC,MAAM,EAAE,YAAY;IAI1B,SAAS,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAG9D;AAoBD,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErD;AA6KD,wBAAgB,cAAc,CAC5B,MAAM,EAAE,YAAY,EACpB,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,aAAa,GAC3B,OAAO,CAET"}
|
package/out/runtime.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getNodeBundler = exports.SandboxBundler = void 0;
|
|
3
|
+
exports.getNodeBundler = exports.userCodePath = exports.SandboxBundler = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
+
const promises_1 = tslib_1.__importDefault(require("fs/promises"));
|
|
5
7
|
const webpack_1 = tslib_1.__importDefault(require("webpack"));
|
|
6
8
|
var RawSource = webpack_1.default.sources.RawSource;
|
|
9
|
+
const cli_shared_1 = require("@forge/cli-shared");
|
|
7
10
|
const common_1 = require("./config/common");
|
|
8
11
|
const sandbox_1 = require("./config/sandbox");
|
|
12
|
+
const typescript_1 = require("./typescript");
|
|
9
13
|
const webpack_2 = require("./webpack");
|
|
14
|
+
const i18n_1 = require("@forge/i18n");
|
|
10
15
|
class SandboxBundler extends webpack_2.WebpackBundler {
|
|
11
16
|
constructor(logger) {
|
|
12
17
|
super(logger);
|
|
@@ -20,6 +25,10 @@ const NODE_RUNTIME_CODE_FILE = '__forge__.js';
|
|
|
20
25
|
const NODE_RUNTIME_BACKUP_WRAPPER_FILE = '__forge_wrapper__.cjs';
|
|
21
26
|
const NODE_RUNTIME_VERSION_FILE = 'runtime.json';
|
|
22
27
|
const NODE_WEBPACK_USER_CODE_DIR = 'bundled';
|
|
28
|
+
function userCodePath(entryKey) {
|
|
29
|
+
return path_1.default.join(path_1.default.dirname(entryKey), NODE_WEBPACK_USER_CODE_DIR, path_1.default.basename(entryKey));
|
|
30
|
+
}
|
|
31
|
+
exports.userCodePath = userCodePath;
|
|
23
32
|
async function emitWrapperFiles(provider, entrypoints, emit, useSingleWrapper) {
|
|
24
33
|
const wrapper = await provider.getNodeRuntimeWrapper();
|
|
25
34
|
const loader = await provider.getNodeRuntimeLoader();
|
|
@@ -41,6 +50,12 @@ async function emitWrapperFiles(provider, entrypoints, emit, useSingleWrapper) {
|
|
|
41
50
|
}
|
|
42
51
|
await emit(NODE_RUNTIME_VERSION_FILE, JSON.stringify({ version: entrypointScript.version }, null, 2));
|
|
43
52
|
}
|
|
53
|
+
async function emitI18nFiles(i18nResourceBundle, emit) {
|
|
54
|
+
await Promise.all((0, cli_shared_1.listFilesInI18nResourceBundle)(i18nResourceBundle).map(async ([fileName, filePath]) => {
|
|
55
|
+
const fileContent = await promises_1.default.readFile(filePath);
|
|
56
|
+
await emit(path_1.default.join(i18n_1.I18N_BUNDLE_FOLDER_NAME, fileName), fileContent.toString());
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
44
59
|
class NodeBundler extends webpack_2.WebpackBundler {
|
|
45
60
|
wrapperProvider;
|
|
46
61
|
statsigReader;
|
|
@@ -52,11 +67,7 @@ class NodeBundler extends webpack_2.WebpackBundler {
|
|
|
52
67
|
async getConfig(args) {
|
|
53
68
|
const webpackConfig = (0, common_1.getCommonWebpackConfig)(args);
|
|
54
69
|
if (!(await this.statsigReader.packageSingleWrapper())) {
|
|
55
|
-
|
|
56
|
-
for (const [entryKey, entryPath] of Object.entries(webpackConfig.entry)) {
|
|
57
|
-
newEntries[`${NODE_WEBPACK_USER_CODE_DIR}/${entryKey}`] = entryPath;
|
|
58
|
-
}
|
|
59
|
-
webpackConfig.entry = newEntries;
|
|
70
|
+
webpackConfig.entry = Object.fromEntries(Object.entries(webpackConfig.entry).map(([entryKey, entryPath]) => [userCodePath(entryKey), entryPath]));
|
|
60
71
|
}
|
|
61
72
|
webpackConfig.target = 'node18';
|
|
62
73
|
webpackConfig.output.filename = '[name].cjs';
|
|
@@ -69,13 +80,67 @@ class NodeBundler extends webpack_2.WebpackBundler {
|
|
|
69
80
|
});
|
|
70
81
|
webpackConfig.plugins.push({
|
|
71
82
|
apply: (compiler) => {
|
|
72
|
-
compiler.hooks.make.tapPromise('AfterEmitPlugin', async (compilation) =>
|
|
83
|
+
compiler.hooks.make.tapPromise('AfterEmitPlugin', async (compilation) => {
|
|
84
|
+
const emit = async (name, contents) => compilation.emitAsset(name, new RawSource(contents));
|
|
85
|
+
await emitWrapperFiles(this.wrapperProvider, args.entryPoints, emit, await this.statsigReader.packageSingleWrapper());
|
|
86
|
+
if (args.i18nResourceBundle) {
|
|
87
|
+
await emitI18nFiles(args.i18nResourceBundle, emit);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
73
90
|
}
|
|
74
91
|
});
|
|
75
92
|
return webpackConfig;
|
|
76
93
|
}
|
|
77
94
|
}
|
|
95
|
+
class TypeScriptNodeBundler extends typescript_1.TypeScriptBundler {
|
|
96
|
+
wrapperProvider;
|
|
97
|
+
statsigReader;
|
|
98
|
+
constructor(logger, wrapperProvider, statsigReader) {
|
|
99
|
+
super(logger);
|
|
100
|
+
this.wrapperProvider = wrapperProvider;
|
|
101
|
+
this.statsigReader = statsigReader;
|
|
102
|
+
}
|
|
103
|
+
async getResult(args, outputDir) {
|
|
104
|
+
if (!(await this.statsigReader.packageSingleWrapper())) {
|
|
105
|
+
throw new cli_shared_1.UserError('Single wrapper feature flag must be enabled to use the TypeScript bundler.');
|
|
106
|
+
}
|
|
107
|
+
const result = await super.getResult(args, outputDir);
|
|
108
|
+
const emit = async (name, contents) => {
|
|
109
|
+
const outputPath = path_1.default.join(outputDir, name);
|
|
110
|
+
await promises_1.default.mkdir(path_1.default.dirname(outputPath), { recursive: true });
|
|
111
|
+
await promises_1.default.writeFile(outputPath, contents);
|
|
112
|
+
};
|
|
113
|
+
await emitWrapperFiles(this.wrapperProvider, args.entryPoints, emit, true);
|
|
114
|
+
if (args.i18nResourceBundle) {
|
|
115
|
+
await emitI18nFiles(args.i18nResourceBundle, emit);
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class ConfigBundler {
|
|
121
|
+
configReader;
|
|
122
|
+
bundlers;
|
|
123
|
+
constructor(logger, wrapperProvider, configReader, statsigReader) {
|
|
124
|
+
this.configReader = configReader;
|
|
125
|
+
this.bundlers = new Map([
|
|
126
|
+
['webpack', new NodeBundler(logger, wrapperProvider, statsigReader)],
|
|
127
|
+
['typescript', new TypeScriptNodeBundler(logger, wrapperProvider, statsigReader)]
|
|
128
|
+
]);
|
|
129
|
+
}
|
|
130
|
+
async getBundlerType() {
|
|
131
|
+
return (await this.configReader.readConfig()).app.package?.bundler ?? 'webpack';
|
|
132
|
+
}
|
|
133
|
+
async getBundler() {
|
|
134
|
+
return this.bundlers.get(await this.getBundlerType());
|
|
135
|
+
}
|
|
136
|
+
async bundle(args) {
|
|
137
|
+
return (await this.getBundler()).bundle(args);
|
|
138
|
+
}
|
|
139
|
+
async watch(args, watch) {
|
|
140
|
+
return (await this.getBundler()).watch(args, watch);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
78
143
|
function getNodeBundler(logger, wrapperProvider, configReader, statsigReader) {
|
|
79
|
-
return new
|
|
144
|
+
return new ConfigBundler(logger, wrapperProvider, configReader, statsigReader);
|
|
80
145
|
}
|
|
81
146
|
exports.getNodeBundler = getNodeBundler;
|
package/out/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger, UserError } from '@forge/cli-shared';
|
|
1
|
+
import { I18nResourceBundle, Logger, UserError } from '@forge/cli-shared';
|
|
2
2
|
import { Translations } from '@forge/manifest';
|
|
3
3
|
export declare type BundlerMetadata = {
|
|
4
4
|
modules?: string[];
|
|
@@ -16,8 +16,9 @@ export declare type EntryPoint = {
|
|
|
16
16
|
export declare type BundlerArgs = {
|
|
17
17
|
appDirectory: string;
|
|
18
18
|
entryPoints: EntryPoint[];
|
|
19
|
-
i18nConfig?: Translations;
|
|
20
19
|
watchMode?: BundlerWatchMode;
|
|
20
|
+
i18nConfig?: Translations;
|
|
21
|
+
i18nResourceBundle?: I18nResourceBundle;
|
|
21
22
|
};
|
|
22
23
|
export declare type BundlerWatchArgs = BundlerArgs & Required<Pick<BundlerArgs, 'watchMode'>> & {
|
|
23
24
|
successMessage: string;
|
package/out/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,oBAAY,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,oBAAY,YAAY,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAEvF,oBAAY,gBAAgB,GAAG,OAAO,GAAG,OAAO,CAAC;AAEjD,oBAAY,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,oBAAY,WAAW,GAAG;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC,CAAC;AAEF,oBAAY,gBAAgB,GAAG,WAAW,GACxC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,GAAG;IACzC,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEJ,oBAAY,YAAY,GAAG;IACzB,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,eAAe,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;CAC1G,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,IAAI,IAAI,IAAI,CAAC;CACd;AAED,oBAAY,kBAAkB,GAAG,cAAc,GAAG;IAChD,MAAM,EAAE,aAAa,CAAC;CACvB,CAAC;AAEF,oBAAY,OAAO,GAAG;IACpB,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IAClD,KAAK,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;CACjF,CAAC;AAEF,qBAAa,YAAa,SAAQ,SAAS;CAAG"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ChildProcessByStdio } from 'child_process';
|
|
4
|
+
import { Readable } from 'stream';
|
|
5
|
+
import { Bundler, BundleLogger, BundlerOutput, BundlerArgs, BundlerWatch, BundlerWatchArgs, BundlerWatchOutput } from './types';
|
|
6
|
+
declare type OutputProcess = ChildProcessByStdio<null, Readable, null>;
|
|
7
|
+
export declare abstract class TypeScriptBundler implements Bundler {
|
|
8
|
+
protected readonly logger: BundleLogger;
|
|
9
|
+
constructor(logger: BundleLogger);
|
|
10
|
+
protected runTypeScript(args: BundlerArgs, outputDir: string): OutputProcess;
|
|
11
|
+
protected getResult(args: BundlerArgs, outputDir: string): Promise<BundlerOutput>;
|
|
12
|
+
bundle(args: BundlerArgs): Promise<BundlerOutput>;
|
|
13
|
+
watch(args: BundlerWatchArgs, watch: BundlerWatch): Promise<BundlerWatchOutput>;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=typescript.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typescript.d.ts","sourceRoot":"","sources":["../src/typescript.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAIpD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AASlC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,aAAa,EACb,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,SAAS,CAAC;AAEjB,aAAK,aAAa,GAAG,mBAAmB,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AA6B/D,8BAAsB,iBAAkB,YAAW,OAAO;IAC5C,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,YAAY;gBAApB,MAAM,EAAE,YAAY;IAEnD,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,aAAa;cAqB5D,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAKjF,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAyBjD,KAAK,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA2DtF"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TypeScriptBundler = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const readline_1 = require("readline");
|
|
8
|
+
const cross_spawn_1 = tslib_1.__importDefault(require("cross-spawn"));
|
|
9
|
+
const cli_shared_1 = require("@forge/cli-shared");
|
|
10
|
+
const common_1 = require("./common");
|
|
11
|
+
const dependencies_1 = require("./dependencies");
|
|
12
|
+
const text_1 = require("./text");
|
|
13
|
+
const COPY_DEPENDENCIES_OPTIONS = {
|
|
14
|
+
exclude: ['@forge/react', '@forge/bridge']
|
|
15
|
+
};
|
|
16
|
+
class TypeScriptBundler {
|
|
17
|
+
logger;
|
|
18
|
+
constructor(logger) {
|
|
19
|
+
this.logger = logger;
|
|
20
|
+
}
|
|
21
|
+
runTypeScript(args, outputDir) {
|
|
22
|
+
const processArgs = [];
|
|
23
|
+
processArgs.push('--project', args.appDirectory);
|
|
24
|
+
processArgs.push('--rootDir', path_1.default.join(args.appDirectory, common_1.SOURCE_DIR));
|
|
25
|
+
if (args.watchMode) {
|
|
26
|
+
processArgs.push('--watch');
|
|
27
|
+
}
|
|
28
|
+
processArgs.push('--outDir', outputDir);
|
|
29
|
+
let tsc = 'tsc';
|
|
30
|
+
const appTsc = path_1.default.join(args.appDirectory, common_1.NODE_MODULES_DIR, '.bin', 'tsc');
|
|
31
|
+
if ((0, fs_1.existsSync)(appTsc)) {
|
|
32
|
+
tsc = appTsc;
|
|
33
|
+
}
|
|
34
|
+
return (0, cross_spawn_1.default)(tsc, processArgs, { stdio: ['ignore', 'pipe', 'inherit'] });
|
|
35
|
+
}
|
|
36
|
+
async getResult(args, outputDir) {
|
|
37
|
+
return { outputDir, metadata: {} };
|
|
38
|
+
}
|
|
39
|
+
async bundle(args) {
|
|
40
|
+
const outputDir = (0, common_1.getOutputDir)(args);
|
|
41
|
+
await (0, dependencies_1.copyProductionDependencies)(args.appDirectory, outputDir, COPY_DEPENDENCIES_OPTIONS);
|
|
42
|
+
const compiler = this.runTypeScript(args, outputDir);
|
|
43
|
+
const output = [];
|
|
44
|
+
compiler.stdout.on('data', (data) => output.push(data));
|
|
45
|
+
return new Promise((resolve, reject) => compiler.on('exit', async (code) => {
|
|
46
|
+
try {
|
|
47
|
+
if (code !== 0) {
|
|
48
|
+
throw new cli_shared_1.BundlerTSError(text_1.Text.typescriptError(output));
|
|
49
|
+
}
|
|
50
|
+
const result = await this.getResult(args, outputDir);
|
|
51
|
+
resolve(result);
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
reject(e);
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
async watch(args, watch) {
|
|
59
|
+
const outputDir = (0, common_1.getOutputDir)(args);
|
|
60
|
+
await (0, dependencies_1.copyProductionDependencies)(args.appDirectory, outputDir, COPY_DEPENDENCIES_OPTIONS);
|
|
61
|
+
const compiler = this.runTypeScript(args, outputDir);
|
|
62
|
+
let isFirstRun = true;
|
|
63
|
+
const output = [];
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
compiler.on('exit', async () => {
|
|
66
|
+
reject(new cli_shared_1.BundlerTSError(text_1.Text.typescriptError(output)));
|
|
67
|
+
});
|
|
68
|
+
const outputLines = (0, readline_1.createInterface)(compiler.stdout);
|
|
69
|
+
outputLines.on('line', async (line) => {
|
|
70
|
+
if (/Starting (incremental )?compilation/.exec(line)) {
|
|
71
|
+
if (!isFirstRun) {
|
|
72
|
+
await watch.onBuildWillStart();
|
|
73
|
+
}
|
|
74
|
+
output.length = 0;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (!line.includes('Watching for file changes.')) {
|
|
78
|
+
line = line.trim();
|
|
79
|
+
if (line) {
|
|
80
|
+
output.push(line);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const errors = Number(/Found (\d+) error/.exec(line)?.[1] ?? '0');
|
|
86
|
+
if (errors) {
|
|
87
|
+
throw new cli_shared_1.BundlerTSError(text_1.Text.typescriptError(output));
|
|
88
|
+
}
|
|
89
|
+
const result = await this.getResult(args, outputDir);
|
|
90
|
+
if (isFirstRun) {
|
|
91
|
+
isFirstRun = false;
|
|
92
|
+
this.logger.info(cli_shared_1.LogColor.trace(args.successMessage));
|
|
93
|
+
resolve({ result, stop: () => compiler.kill() });
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
await watch.onBuildFinished(null, result);
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
if (isFirstRun) {
|
|
100
|
+
isFirstRun = false;
|
|
101
|
+
reject(e);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
await watch.onBuildFinished(e);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.TypeScriptBundler = TypeScriptBundler;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@forge/bundler",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.22.0-next.16",
|
|
4
4
|
"description": "Default bundler for Forge apps",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"author": "Atlassian",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"@babel/plugin-transform-optional-chaining": "^7.23.4",
|
|
20
20
|
"@babel/plugin-transform-react-jsx": "^7.23.4",
|
|
21
21
|
"@babel/preset-typescript": "^7.23.3",
|
|
22
|
-
"@forge/api": "5.
|
|
22
|
+
"@forge/api": "5.2.0-next.0",
|
|
23
23
|
"@forge/babel-plugin-transform-ui": "1.1.21",
|
|
24
|
-
"@forge/cli-shared": "6.8.0-next.
|
|
25
|
-
"@forge/i18n": "0.0.
|
|
26
|
-
"@forge/lint": "5.7.3-next.
|
|
27
|
-
"@forge/manifest": "8.9.0-next.
|
|
24
|
+
"@forge/cli-shared": "6.8.0-next.15",
|
|
25
|
+
"@forge/i18n": "0.0.5-next.0",
|
|
26
|
+
"@forge/lint": "5.7.3-next.16",
|
|
27
|
+
"@forge/manifest": "8.9.0-next.8",
|
|
28
28
|
"@forge/util": "1.4.8",
|
|
29
29
|
"assert": "^2.1.0",
|
|
30
30
|
"babel-loader": "^8.3.0",
|
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
"chalk": "^4.1.2",
|
|
34
34
|
"cheerio": "^0.22.0",
|
|
35
35
|
"console-browserify": "^1.2.0",
|
|
36
|
+
"cross-spawn": "^7.0.5",
|
|
36
37
|
"crypto-browserify": "^3.12.0",
|
|
37
38
|
"events": "^3.3.0",
|
|
39
|
+
"fs-extra": "^11.2.0",
|
|
38
40
|
"headers-utils": "^3.0.2",
|
|
39
41
|
"html-webpack-plugin": "^5.6.0",
|
|
40
42
|
"inherits": "^2.0.4",
|
|
@@ -62,6 +64,8 @@
|
|
|
62
64
|
"devDependencies": {
|
|
63
65
|
"@atlassian/xen-test-util": "^4.2.0",
|
|
64
66
|
"@forge/runtime": "5.10.7",
|
|
67
|
+
"@types/cross-spawn": "^6.0.6",
|
|
68
|
+
"@types/fs-extra": "^11.0.4",
|
|
65
69
|
"@types/jest": "^29.5.12",
|
|
66
70
|
"@types/node": "14.18.63",
|
|
67
71
|
"@types/react": "^18.2.64",
|
|
@@ -72,6 +76,7 @@
|
|
|
72
76
|
"eslint": "^8.56.0",
|
|
73
77
|
"eslint-config-prettier": "^9.1.0",
|
|
74
78
|
"eslint-plugin-prettier": "^5.1.3",
|
|
79
|
+
"glob": "^10.3.10",
|
|
75
80
|
"jest-matcher-specific-error": "^1.0.0",
|
|
76
81
|
"prettier": "3.2.5"
|
|
77
82
|
},
|