@forge/bundler 6.1.3 → 6.1.4-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @forge/bundler
2
2
 
3
+ ## 6.1.4-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - bda7c8d: Send 'app packaged' analytics event
8
+ - Updated dependencies [bda7c8d]
9
+ - @forge/cli-shared@8.5.0-next.1
10
+ - @forge/lint@5.10.3-next.1
11
+
12
+ ## 6.1.4-next.0
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [be30715]
17
+ - @forge/cli-shared@8.5.0-next.0
18
+ - @forge/lint@5.10.3-next.0
19
+
3
20
  ## 6.1.3
4
21
 
5
22
  ### Patch Changes
package/out/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export { getOutputDir, getEntryPoints } from './common';
2
2
  export { runLinter } from './lint';
3
3
  export { NativeUIBundler, NativeUIBundleResult } from './nativeui';
4
4
  export { getNodeBundler, NODE_RUNTIME_CODE_FILE } from './runtime';
5
- export { Bundler, BundlerError, BundlerOutput, BundlerWatch, EntryPoint, WatcherMonitor } from './types';
5
+ export { Bundler, BundlerError, BundlerMetadata, emptyMetadata, mergeMetadata, BundlerOutput, BundlerWatch, EntryPoint, WatcherMonitor } from './types';
6
6
  export { getCompiler, handleWebpackCompilationResult } from './webpack';
7
7
  export { getNativeUiBuildConfig } from './config/nativeui';
8
8
  export { getWrapperProvider, LocalWrapperProvider } from './wrapper-provider';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,8BAA8B,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnE,OAAO,EACL,OAAO,EACP,YAAY,EACZ,eAAe,EACf,aAAa,EACb,aAAa,EACb,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,WAAW,EAAE,8BAA8B,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
package/out/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LocalWrapperProvider = exports.getWrapperProvider = exports.getNativeUiBuildConfig = exports.handleWebpackCompilationResult = exports.getCompiler = exports.BundlerError = exports.NODE_RUNTIME_CODE_FILE = exports.getNodeBundler = exports.NativeUIBundler = exports.runLinter = exports.getEntryPoints = exports.getOutputDir = void 0;
3
+ exports.LocalWrapperProvider = exports.getWrapperProvider = exports.getNativeUiBuildConfig = exports.handleWebpackCompilationResult = exports.getCompiler = exports.mergeMetadata = exports.emptyMetadata = exports.BundlerError = exports.NODE_RUNTIME_CODE_FILE = exports.getNodeBundler = exports.NativeUIBundler = exports.runLinter = exports.getEntryPoints = exports.getOutputDir = void 0;
4
4
  var common_1 = require("./common");
5
5
  Object.defineProperty(exports, "getOutputDir", { enumerable: true, get: function () { return common_1.getOutputDir; } });
6
6
  Object.defineProperty(exports, "getEntryPoints", { enumerable: true, get: function () { return common_1.getEntryPoints; } });
@@ -13,6 +13,8 @@ Object.defineProperty(exports, "getNodeBundler", { enumerable: true, get: functi
13
13
  Object.defineProperty(exports, "NODE_RUNTIME_CODE_FILE", { enumerable: true, get: function () { return runtime_1.NODE_RUNTIME_CODE_FILE; } });
14
14
  var types_1 = require("./types");
15
15
  Object.defineProperty(exports, "BundlerError", { enumerable: true, get: function () { return types_1.BundlerError; } });
16
+ Object.defineProperty(exports, "emptyMetadata", { enumerable: true, get: function () { return types_1.emptyMetadata; } });
17
+ Object.defineProperty(exports, "mergeMetadata", { enumerable: true, get: function () { return types_1.mergeMetadata; } });
16
18
  var webpack_1 = require("./webpack");
17
19
  Object.defineProperty(exports, "getCompiler", { enumerable: true, get: function () { return webpack_1.getCompiler; } });
18
20
  Object.defineProperty(exports, "handleWebpackCompilationResult", { enumerable: true, get: function () { return webpack_1.handleWebpackCompilationResult; } });
@@ -0,0 +1,3 @@
1
+ import { BundleLogger, BundlerMetadata } from './types';
2
+ export declare function getMetadata(logger: BundleLogger, files: string[]): Promise<BundlerMetadata>;
3
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,YAAY,EAAE,eAAe,EAAiB,MAAM,SAAS,CAAC;AASvE,wBAAsB,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CAqBjG"}
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMetadata = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const promises_1 = require("fs/promises");
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const parser = tslib_1.__importStar(require("@babel/parser"));
8
+ const traverse_1 = tslib_1.__importDefault(require("@babel/traverse"));
9
+ const text_1 = require("./text");
10
+ const types_1 = require("./types");
11
+ async function getMetadata(logger, files) {
12
+ const metadata = (0, types_1.emptyMetadata)();
13
+ const packageJson = await warnIfFailed(logger, async () => {
14
+ try {
15
+ await (0, promises_1.access)('package.json');
16
+ }
17
+ catch {
18
+ return undefined;
19
+ }
20
+ const packageFile = await (0, promises_1.readFile)('package.json', 'utf8');
21
+ return JSON.parse(packageFile);
22
+ });
23
+ if (packageJson?.type === 'module') {
24
+ metadata.esm = true;
25
+ }
26
+ await Promise.all(files.map((filePath) => warnIfFailed(logger, async () => processFile(metadata, filePath))));
27
+ return metadata;
28
+ }
29
+ exports.getMetadata = getMetadata;
30
+ function packageFromImport(name) {
31
+ const parts = name.split('/');
32
+ if (parts.length === 0 || parts[0] === '') {
33
+ return '';
34
+ }
35
+ if (parts[0].startsWith('@')) {
36
+ return `${parts[0]}/${parts[1]}`;
37
+ }
38
+ if (parts[0].startsWith('node:')) {
39
+ return parts[0].substring(5);
40
+ }
41
+ return parts[0];
42
+ }
43
+ async function processFile(metadata, filePath) {
44
+ const ext = path_1.default.extname(filePath);
45
+ if (ext.match(/^\.[cm]?jsx?$/)) {
46
+ metadata.jsFiles++;
47
+ }
48
+ else if (ext.match(/^\.[cm]?tsx?$/)) {
49
+ metadata.tsFiles++;
50
+ }
51
+ else if (ext === '.json') {
52
+ return;
53
+ }
54
+ const source = await (0, promises_1.readFile)(filePath, 'utf8');
55
+ const ast = parser.parse(source, {
56
+ sourceType: 'module',
57
+ plugins: ['typescript', 'jsx']
58
+ });
59
+ (0, traverse_1.default)(ast, {
60
+ ImportDeclaration: ({ node }) => {
61
+ const packageName = packageFromImport(node.source.value);
62
+ metadata.dependencies.add(packageName);
63
+ if (packageName.startsWith('@forge/')) {
64
+ for (const specifier of node.specifiers) {
65
+ let member;
66
+ switch (specifier.type) {
67
+ case 'ImportDefaultSpecifier':
68
+ case 'ImportNamespaceSpecifier':
69
+ member = '*';
70
+ break;
71
+ case 'ImportSpecifier':
72
+ switch (specifier.imported.type) {
73
+ case 'Identifier':
74
+ member = specifier.imported.name;
75
+ break;
76
+ case 'StringLiteral':
77
+ member = specifier.imported.value;
78
+ break;
79
+ }
80
+ }
81
+ metadata.sdkImports.add(`${packageName}.${member}`);
82
+ }
83
+ }
84
+ }
85
+ });
86
+ }
87
+ async function warnIfFailed(logger, action) {
88
+ try {
89
+ return await action();
90
+ }
91
+ catch (error) {
92
+ logger.warn(text_1.Text.metadataFailed(error));
93
+ }
94
+ }
package/out/nativeui.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { ResourceDetails } from '@forge/cli-shared';
2
2
  import { Translations } from '@forge/manifest';
3
- import { BundlerArgs } from './types';
3
+ import { BundlerArgs, BundlerMetadata } from './types';
4
4
  import { ConfigWithOutput, WebpackBundler } from './webpack';
5
5
  export interface NativeUIBundleResult {
6
6
  nativeUiBundlesDetails: ResourceDetails[];
7
+ metadata: BundlerMetadata;
7
8
  }
8
9
  export declare class NativeUIBundler extends WebpackBundler {
9
10
  getConfig({ entryPoints, i18nConfig }: BundlerArgs): Promise<ConfigWithOutput>;
@@ -1 +1 @@
1
- {"version":3,"file":"nativeui.d.ts","sourceRoot":"","sources":["../src/nativeui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAA+B,MAAM,SAAS,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE7D,MAAM,WAAW,oBAAoB;IACnC,sBAAsB,EAAE,eAAe,EAAE,CAAC;CAC3C;AAED,qBAAa,eAAgB,SAAQ,cAAc;IAC3C,SAAS,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIvE,eAAe,CAAC,SAAS,EAAE,eAAe,EAAE,EAAE,UAAU,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAmCrH"}
1
+ {"version":3,"file":"nativeui.d.ts","sourceRoot":"","sources":["../src/nativeui.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAgB,eAAe,EAA+C,MAAM,SAAS,CAAC;AAClH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE7D,MAAM,WAAW,oBAAoB;IACnC,sBAAsB,EAAE,eAAe,EAAE,CAAC;IAC1C,QAAQ,EAAE,eAAe,CAAC;CAC3B;AAED,qBAAa,eAAgB,SAAQ,cAAc;IAC3C,SAAS,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIvE,eAAe,CAAC,SAAS,EAAE,eAAe,EAAE,EAAE,UAAU,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,oBAAoB,CAAC;CAyCrH"}
package/out/nativeui.js CHANGED
@@ -10,6 +10,7 @@ class NativeUIBundler extends webpack_1.WebpackBundler {
10
10
  }
11
11
  async bundleResources(resources, i18nConfig) {
12
12
  const nativeUiBundlesDetails = [];
13
+ let combinedMetadata = (0, types_1.emptyMetadata)();
13
14
  await Promise.all(resources.map(async (resource) => {
14
15
  const entryPoint = {
15
16
  name: resource.key,
@@ -26,15 +27,19 @@ class NativeUIBundler extends webpack_1.WebpackBundler {
26
27
  catch (e) {
27
28
  throw new types_1.BundlerError(e.message);
28
29
  }
29
- const { outputDir } = bundlerOutput;
30
+ const { outputDir, metadata } = bundlerOutput;
30
31
  this.logger.debug(`NativeUI bundle created: ${outputDir}`);
31
32
  nativeUiBundlesDetails.push({
32
33
  ...resource,
33
34
  path: outputDir
34
35
  });
36
+ if (metadata) {
37
+ combinedMetadata = (0, types_1.mergeMetadata)(combinedMetadata, metadata);
38
+ }
35
39
  }));
36
40
  return {
37
- nativeUiBundlesDetails
41
+ nativeUiBundlesDetails,
42
+ metadata: combinedMetadata
38
43
  };
39
44
  }
40
45
  }
package/out/runtime.js CHANGED
@@ -80,8 +80,8 @@ class TypeScriptNodeBundler extends typescript_1.TypeScriptBundler {
80
80
  super(logger);
81
81
  this.wrapperProvider = wrapperProvider;
82
82
  }
83
- async getResult(args, outputDir) {
84
- const result = await super.getResult(args, outputDir);
83
+ async getResult(args, outputDir, output) {
84
+ const result = await super.getResult(args, outputDir, output);
85
85
  const emit = async (name, contents) => {
86
86
  const outputPath = path_1.default.join(outputDir, name);
87
87
  await promises_1.default.mkdir(path_1.default.dirname(outputPath), { recursive: true });
package/out/text.d.ts CHANGED
@@ -2,6 +2,6 @@ export declare const Text: {
2
2
  genericBundlingError: (errors: string[]) => string;
3
3
  typescriptError: (errors: string[]) => string;
4
4
  noExecutableFile: string;
5
- unsupported: (requestedModule: string) => string;
5
+ metadataFailed: (error: Error) => string;
6
6
  };
7
7
  //# sourceMappingURL=text.d.ts.map
package/out/text.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI;mCACgB,MAAM,EAAE;8BACb,MAAM,EAAE;;mCAKH,MAAM;CAEtC,CAAC"}
1
+ {"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI;mCACgB,MAAM,EAAE;8BACb,MAAM,EAAE;;4BAKV,KAAK;CAC9B,CAAC"}
package/out/text.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Text = void 0;
4
4
  exports.Text = {
5
5
  genericBundlingError: (errors) => `Bundling failed: ${errors.join(', ')}`,
6
- typescriptError: (errors) => `TypeScript errors in the app caused the bundling to fail. Fix the errors listed below before rerunning the command. ${errors.join('')}`,
6
+ typescriptError: (errors) => `TypeScript errors in the app caused the bundling to fail. Fix the errors listed below before rerunning the command. ${errors.join('\n')}`,
7
7
  noExecutableFile: 'Could not find the main executable file',
8
- unsupported: (requestedModule) => `⚠️ the '${requestedModule}' module is not supported by Forge, please refer to the documentation at https://go.atlassian.com/forge-runtime-js-environment`
8
+ metadataFailed: (error) => `Application code metadata processing failed: ${error.message}`
9
9
  };
package/out/types.d.ts CHANGED
@@ -2,7 +2,14 @@ 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[];
5
+ jsFiles: number;
6
+ tsFiles: number;
7
+ esm: boolean;
8
+ dependencies: Set<string>;
9
+ sdkImports: Set<string>;
5
10
  };
11
+ export declare function emptyMetadata(): BundlerMetadata;
12
+ export declare function mergeMetadata(metadata1: BundlerMetadata, metadata2: BundlerMetadata): BundlerMetadata;
6
13
  export interface BundlerOutput {
7
14
  outputDir: string;
8
15
  metadata?: BundlerMetadata;
@@ -1 +1 @@
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,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E,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"}
package/out/types.js CHANGED
@@ -1,7 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BundlerError = void 0;
3
+ exports.BundlerError = exports.mergeMetadata = exports.emptyMetadata = void 0;
4
4
  const cli_shared_1 = require("@forge/cli-shared");
5
+ function emptyMetadata() {
6
+ return {
7
+ jsFiles: 0,
8
+ tsFiles: 0,
9
+ esm: false,
10
+ dependencies: new Set(),
11
+ sdkImports: new Set()
12
+ };
13
+ }
14
+ exports.emptyMetadata = emptyMetadata;
15
+ function mergeMetadata(metadata1, metadata2) {
16
+ return {
17
+ ...((metadata1.modules || metadata2.modules) && {
18
+ modules: [...(metadata1.modules ?? []), ...(metadata2.modules ?? [])]
19
+ }),
20
+ jsFiles: metadata1.jsFiles + metadata2.jsFiles,
21
+ tsFiles: metadata1.tsFiles + metadata2.tsFiles,
22
+ esm: metadata1.esm || metadata2.esm,
23
+ dependencies: new Set([...metadata1.dependencies, ...metadata2.dependencies]),
24
+ sdkImports: new Set([...metadata1.sdkImports, ...metadata2.sdkImports])
25
+ };
26
+ }
27
+ exports.mergeMetadata = mergeMetadata;
5
28
  class BundlerError extends cli_shared_1.UserError {
6
29
  }
7
30
  exports.BundlerError = BundlerError;
@@ -8,7 +8,9 @@ export declare abstract class TypeScriptBundler implements Bundler {
8
8
  protected readonly logger: BundleLogger;
9
9
  constructor(logger: BundleLogger);
10
10
  protected runTypeScript(args: BundlerArgs, outputDir: string): OutputProcess;
11
- protected getResult(args: BundlerArgs, outputDir: string): Promise<BundlerOutput>;
11
+ protected isListedFile(line: string): string | null;
12
+ protected isAppFile(line: string): string | null;
13
+ protected getResult(args: BundlerArgs, outputDir: string, output?: string): Promise<BundlerOutput>;
12
14
  bundle(args: BundlerArgs): Promise<BundlerOutput>;
13
15
  watch(args: BundlerWatchArgs, watch: BundlerWatch): Promise<BundlerWatchOutput>;
14
16
  }
@@ -1 +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,EACn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S,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;cAUhC,SAAS,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IAiBlG,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IA6BjD,KAAK,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;CA2DtF"}
package/out/typescript.js CHANGED
@@ -10,6 +10,8 @@ const cli_shared_1 = require("@forge/cli-shared");
10
10
  const common_1 = require("./common");
11
11
  const dependencies_1 = require("./dependencies");
12
12
  const text_1 = require("./text");
13
+ const types_1 = require("./types");
14
+ const metadata_1 = require("./metadata");
13
15
  const COPY_DEPENDENCIES_OPTIONS = {
14
16
  exclude: ['@forge/react', '@forge/bridge']
15
17
  };
@@ -25,6 +27,9 @@ class TypeScriptBundler {
25
27
  if (args.watchMode) {
26
28
  processArgs.push('--watch');
27
29
  }
30
+ else {
31
+ processArgs.push('--listFiles');
32
+ }
28
33
  processArgs.push('--outDir', outputDir);
29
34
  let tsc = 'tsc';
30
35
  const appTsc = path_1.default.join(args.appDirectory, common_1.NODE_MODULES_DIR, '.bin', 'tsc');
@@ -33,21 +38,55 @@ class TypeScriptBundler {
33
38
  }
34
39
  return (0, cross_spawn_1.default)(tsc, processArgs, { stdio: ['ignore', 'pipe', 'inherit'] });
35
40
  }
36
- async getResult(args, outputDir) {
37
- return { outputDir, metadata: {} };
41
+ isListedFile(line) {
42
+ line = line.trim();
43
+ if (line.length === 0) {
44
+ return null;
45
+ }
46
+ if (!line.match(/^\/.+\.[cm]?[jt]sx?$/)) {
47
+ return null;
48
+ }
49
+ return line;
50
+ }
51
+ isAppFile(line) {
52
+ if (!this.isListedFile(line)) {
53
+ return null;
54
+ }
55
+ if (line.includes('node_modules/')) {
56
+ return null;
57
+ }
58
+ return line;
59
+ }
60
+ async getResult(args, outputDir, output) {
61
+ let metadata;
62
+ if (output) {
63
+ const files = [];
64
+ for (const line of output.split('\n')) {
65
+ const filePath = this.isAppFile(line);
66
+ if (filePath) {
67
+ files.push(filePath);
68
+ }
69
+ }
70
+ metadata = await (0, metadata_1.getMetadata)(this.logger, files);
71
+ }
72
+ else {
73
+ metadata = (0, types_1.emptyMetadata)();
74
+ }
75
+ return { outputDir, metadata };
38
76
  }
39
77
  async bundle(args) {
40
78
  const outputDir = (0, common_1.getOutputDir)(args);
41
79
  await (0, dependencies_1.copyProductionDependencies)(args.appDirectory, outputDir, COPY_DEPENDENCIES_OPTIONS);
42
80
  const compiler = this.runTypeScript(args, outputDir);
43
- const output = [];
44
- compiler.stdout.on('data', (data) => output.push(data));
81
+ let output = '';
82
+ compiler.stdout.on('data', (data) => (output += data.toString()));
45
83
  return new Promise((resolve, reject) => compiler.on('exit', async (code) => {
46
84
  try {
47
85
  if (code !== 0) {
48
- throw new cli_shared_1.BundlerTSError(text_1.Text.typescriptError(output));
86
+ const errors = output.split('\n').filter((line) => !this.isListedFile(line));
87
+ throw new cli_shared_1.BundlerTSError(text_1.Text.typescriptError(errors));
49
88
  }
50
- const result = await this.getResult(args, outputDir);
89
+ const result = await this.getResult(args, outputDir, output);
51
90
  resolve(result);
52
91
  }
53
92
  catch (e) {
package/out/webpack.d.ts CHANGED
@@ -10,6 +10,8 @@ export declare abstract class WebpackBundler implements Bundler {
10
10
  protected readonly logger: BundleLogger;
11
11
  constructor(logger: BundleLogger);
12
12
  protected getOutput(config: ConfigWithOutput, stats: webpack.Stats): Promise<BundlerOutput>;
13
+ protected isLocalModule(name: string): boolean;
14
+ protected localModules(stats: webpack.Stats): string[];
13
15
  protected runCompiler(config: ConfigWithOutput): Promise<BundlerOutput>;
14
16
  abstract getConfig(args: BundlerArgs): Promise<ConfigWithOutput>;
15
17
  bundle(args: BundlerArgs): Promise<BundlerOutput>;
@@ -1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,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAE1D,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC;IAKjD,KAAK,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAsCtF"}
package/out/webpack.js CHANGED
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebpackBundler = exports.getCompiler = exports.handleWebpackCompilationResult = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
5
6
  const webpack_1 = tslib_1.__importDefault(require("webpack"));
6
7
  const cli_shared_1 = require("@forge/cli-shared");
8
+ const metadata_1 = require("./metadata");
7
9
  const text_1 = require("./text");
8
10
  function handleWebpackCompilationResult(logger, err, stats) {
9
11
  if (err) {
@@ -62,12 +64,51 @@ class WebpackBundler {
62
64
  }
63
65
  async getOutput(config, stats) {
64
66
  const outputDir = config.output.path;
65
- const metadata = {};
67
+ const metadata = await (0, metadata_1.getMetadata)(this.logger, this.localModules(stats));
66
68
  if (stats) {
67
69
  metadata.modules = getNodeModuleNames(stats);
68
70
  }
69
71
  return { outputDir, metadata };
70
72
  }
73
+ isLocalModule(name) {
74
+ if (name.match(/\/node_modules\/(.+)$/)) {
75
+ return false;
76
+ }
77
+ if (name.match(/^external "(?:node:)?([^:"]+)"$/)) {
78
+ return false;
79
+ }
80
+ if (name.startsWith('webpack/runtime/')) {
81
+ return false;
82
+ }
83
+ if (path_1.default.extname(name) === '.json') {
84
+ return false;
85
+ }
86
+ if (!path_1.default.extname(name).match(/^\.[cm]?[jt]sx?$/)) {
87
+ throw new Error(`Unknown module type for ${JSON.stringify(name)}.`);
88
+ }
89
+ return true;
90
+ }
91
+ localModules(stats) {
92
+ const { modules } = stats.toJson({ modules: true });
93
+ const result = [];
94
+ const addModules = (modules) => {
95
+ for (const module of modules) {
96
+ if (module.modules) {
97
+ addModules(module.modules);
98
+ }
99
+ else if (!module.name) {
100
+ throw new Error('Module name is missing');
101
+ }
102
+ else if (this.isLocalModule(module.name)) {
103
+ result.push(module.name);
104
+ }
105
+ }
106
+ };
107
+ if (modules) {
108
+ addModules(modules);
109
+ }
110
+ return result;
111
+ }
71
112
  async runCompiler(config) {
72
113
  const compiler = getCompiler(config);
73
114
  return new Promise((resolve, reject) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@forge/bundler",
3
- "version": "6.1.3",
3
+ "version": "6.1.4-next.1",
4
4
  "description": "Default bundler for Forge apps",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "author": "Atlassian",
@@ -13,14 +13,16 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@babel/core": "^7.24.0",
16
+ "@babel/parser": "7.28.0",
16
17
  "@babel/plugin-transform-class-properties": "^7.23.3",
17
18
  "@babel/plugin-transform-class-static-block": "^7.23.4",
18
19
  "@babel/plugin-transform-numeric-separator": "^7.23.4",
19
20
  "@babel/plugin-transform-optional-chaining": "^7.23.4",
20
21
  "@babel/plugin-transform-react-jsx": "^7.23.4",
21
- "@forge/cli-shared": "8.4.0",
22
+ "@babel/traverse": "^7.24.0",
23
+ "@forge/cli-shared": "8.5.0-next.1",
22
24
  "@forge/i18n": "0.0.7",
23
- "@forge/lint": "5.10.2",
25
+ "@forge/lint": "5.10.3-next.1",
24
26
  "@forge/manifest": "10.3.0",
25
27
  "babel-loader": "^8.3.0",
26
28
  "cheerio": "^1.1.0",
@@ -31,6 +33,7 @@
31
33
  "node-fetch": "2.7.0",
32
34
  "tmp": "^0.2.3",
33
35
  "ts-loader": "^9.5.2",
36
+ "type-fest": "4.10.2",
34
37
  "typescript": "4.8.4",
35
38
  "webpack": "^5.99.9",
36
39
  "webpack-bundle-analyzer": "^4.10.2"