@granite-js/mpack 0.1.16 → 0.1.18

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,25 @@
1
1
  # @granite-js/mpack
2
2
 
3
+ ## 0.1.18
4
+
5
+ ### Patch Changes
6
+
7
+ - @granite-js/devtools-frontend@0.1.18
8
+ - @granite-js/plugin-core@0.1.18
9
+ - @granite-js/utils@0.1.18
10
+
11
+ ## 0.1.17
12
+
13
+ ### Patch Changes
14
+
15
+ - 07d4020: fix getId generation
16
+ - 9c415df: supports dynamic plugin config
17
+ - dfd1a1e: improve uncaught exception
18
+ - Updated dependencies [9c415df]
19
+ - @granite-js/plugin-core@0.1.17
20
+ - @granite-js/devtools-frontend@0.1.17
21
+ - @granite-js/utils@0.1.17
22
+
3
23
  ## 0.1.16
4
24
 
5
25
  ### Patch Changes
@@ -15,6 +15,7 @@ export declare class Bundler {
15
15
  }): Promise<BuildResult>;
16
16
  getId(): INTERNAL__Id;
17
17
  addPlugin(plugin: Plugin): this;
18
+ private setupUncaughtExceptionHandler;
18
19
  private getBaseBuildOptions;
19
20
  private setupEnvironment;
20
21
  private handlePrepare;
@@ -41,9 +41,11 @@ var import_logger = require("../logger");
41
41
  var import_getId = require("../utils/getId");
42
42
  var import_promise = require("../utils/promise");
43
43
  var import_presets = require("./internal/presets");
44
+ var import_progressBar = require("../utils/progressBar");
44
45
  class Bundler {
45
46
  constructor(config) {
46
47
  this.config = config;
48
+ this.setupUncaughtExceptionHandler();
47
49
  const id = (0, import_getId.getId)(config);
48
50
  this.id = id;
49
51
  this.pluginDriver = new import_PluginDriver.PluginDriver(id);
@@ -83,6 +85,18 @@ class Bundler {
83
85
  this.pluginDriver.addPlugin(plugin);
84
86
  return this;
85
87
  }
88
+ setupUncaughtExceptionHandler() {
89
+ if (process.hasUncaughtExceptionCaptureCallback()) {
90
+ return;
91
+ }
92
+ process.setUncaughtExceptionCaptureCallback((error) => {
93
+ (0, import_progressBar.cleanup)();
94
+ import_logger.logger.error(`Uncaught exception occurred
95
+
96
+ ${error.stack ?? error.message}`);
97
+ process.exit(1);
98
+ });
99
+ }
86
100
  getBaseBuildOptions() {
87
101
  const { rootDir, metafile, buildConfig } = this.config;
88
102
  const { platform, entry, outfile = "bundle.js", esbuild: esbuild2 = {} } = buildConfig;
@@ -67,7 +67,8 @@ async function buildAll(optionsList, { config, concurrency = 2 }) {
67
67
  return buildResults;
68
68
  }
69
69
  async function buildImpl(config, { platform, outfile, minify = false, dev = true }) {
70
- const metroConfig = await (0, import_getMetroConfig.getMetroConfig)({ rootPath: config.cwd }, config.metro);
70
+ const resolvedConfig = await (0, import_plugin_core.resolveConfig)(config);
71
+ const metroConfig = await (0, import_getMetroConfig.getMetroConfig)({ rootPath: config.cwd }, resolvedConfig?.metro ?? {});
71
72
  const outfileName = outfile == null ? (0, import_getDefaultOutfileName.getDefaultOutfileName)(config.entryFile, platform) : outfile;
72
73
  const outfilePath = import_path.default.join(config.outdir, outfileName);
73
74
  await import_src.default.runBuild(metroConfig, {
@@ -40,6 +40,7 @@ var import_bundler = require("../bundler");
40
40
  var import_performance = require("../performance");
41
41
  var import_buildResult = require("../utils/buildResult");
42
42
  var import_getDefaultOutfileName = require("../utils/getDefaultOutfileName");
43
+ var import_printErrors = require("../utils/printErrors");
43
44
  var import_promise = require("../utils/promise");
44
45
  var import_writeBundle = require("../utils/writeBundle");
45
46
  async function build({ config, plugins = [], ...options }) {
@@ -64,7 +65,9 @@ async function buildAll(optionsList, { config, plugins = [], concurrency = 2 })
64
65
  }
65
66
  })
66
67
  );
67
- if (taskResults.some(import_promise.isRejected)) {
68
+ const errors = taskResults.filter(import_promise.isRejected);
69
+ if (errors.length) {
70
+ (0, import_printErrors.printErrors)(errors);
68
71
  throw new Error("Build failed");
69
72
  }
70
73
  const buildResults = taskResults.filter(import_promise.isFulfilled).map((result) => result.value);
@@ -72,6 +75,7 @@ async function buildAll(optionsList, { config, plugins = [], concurrency = 2 })
72
75
  return buildResults;
73
76
  }
74
77
  async function buildImpl(config, plugins, { platform, outfile, cache = true, dev = true, metafile = false }) {
78
+ const { metro: _metroConfig, devServer: _devServerConfig, ...buildConfig } = await (0, import_plugin_core.resolveConfig)(config);
75
79
  const outfileName = outfile == null ? (0, import_getDefaultOutfileName.getDefaultOutfileName)(config.entryFile, platform) : outfile;
76
80
  const outfilePath = path.resolve(config.outdir, outfileName);
77
81
  const bundler = new import_bundler.Bundler({
@@ -83,7 +87,7 @@ async function buildImpl(config, plugins, { platform, outfile, cache = true, dev
83
87
  platform,
84
88
  entry: config.entryFile,
85
89
  outfile: outfilePath,
86
- ...config.build
90
+ ...buildConfig
87
91
  }
88
92
  });
89
93
  for (const plugin of plugins) {
@@ -50,9 +50,10 @@ async function EXPERIMENTAL__server({
50
50
  const driver = (0, import_plugin_core.createPluginHooksDriver)(config);
51
51
  await driver.devServer.pre({ host, port });
52
52
  const rootDir = config.cwd;
53
+ const { metro: _, devServer, ...buildConfig } = await (0, import_plugin_core.resolveConfig)(config) ?? {};
53
54
  const server = new import_DevServer.DevServer({
54
- buildConfig: { entry: config.entryFile, ...config.build },
55
- middlewares: config.devServer?.middlewares ?? [],
55
+ buildConfig: { entry: config.entryFile, ...buildConfig },
56
+ middlewares: devServer?.middlewares ?? [],
56
57
  host,
57
58
  port,
58
59
  rootDir
@@ -79,7 +79,8 @@ async function runServer({
79
79
  }
80
80
  }
81
81
  };
82
- const { middlewares = [], ...additionalMetroConfig } = config.metro ?? {};
82
+ const resolvedConfig = await (0, import_plugin_core.resolveConfig)(config);
83
+ const { middlewares = [], ...additionalMetroConfig } = resolvedConfig?.metro ?? {};
83
84
  const baseConfig = await (0, import_getMetroConfig.getMetroConfig)({ rootPath: config.cwd }, additionalMetroConfig);
84
85
  const metroConfig = mergeConfig(baseConfig, {
85
86
  server: { port },
@@ -43,7 +43,6 @@ var import_wss = require("./wss");
43
43
  var import_constants = require("../constants");
44
44
  var import_logger = require("../logger");
45
45
  var import_statusPlugin = require("../plugins/statusPlugin");
46
- var import_PersistentStorage = require("../shared/PersistentStorage");
47
46
  var import_isDebugMode = require("../utils/isDebugMode");
48
47
  var import_progressBar = require("../utils/progressBar");
49
48
  var import_dev_middleware = require("../vendors/@react-native/dev-middleware");
@@ -73,7 +72,6 @@ class DevServer {
73
72
  async initialize() {
74
73
  import_logger.logger.trace("DevServer.initialize");
75
74
  const { rootDir, buildConfig } = this.devServerOptions;
76
- await import_PersistentStorage.persistentStorage.loadData();
77
75
  this.context = await this.createDevServerContext(rootDir, buildConfig);
78
76
  }
79
77
  listen() {
@@ -1,20 +1,18 @@
1
1
  import { INTERNAL__Id } from '../types';
2
- /**
3
- * 파일 시스템에 저장되는 데이터 (캐싱된 메타 데이터)
4
- */
5
2
  interface PersistentData {
6
3
  [id: INTERNAL__Id]: {
7
4
  /**
8
- * 번들링시 resolve 전체 모듈 (progress 계산에 사용)
5
+ * Resolved module count (used for progress bar progress calculation)
9
6
  */
10
7
  totalModuleCount: number;
11
8
  };
12
9
  }
13
10
  declare class PersistentStorage {
14
11
  private data;
12
+ constructor();
15
13
  getData(): PersistentData;
16
14
  setData(newData: Partial<PersistentData>): void;
17
- loadData(): Promise<void>;
15
+ loadData(): void;
18
16
  saveData(): Promise<void>;
19
17
  }
20
18
  export declare const persistentStorage: PersistentStorage;
@@ -31,32 +31,35 @@ __export(PersistentStorage_exports, {
31
31
  persistentStorage: () => persistentStorage
32
32
  });
33
33
  module.exports = __toCommonJS(PersistentStorage_exports);
34
- var fs = __toESM(require("fs/promises"));
34
+ var fs = __toESM(require("fs"));
35
35
  var path = __toESM(require("path"));
36
36
  var import_es_toolkit = require("es-toolkit");
37
37
  var import_constants = require("../constants");
38
38
  class PersistentStorage {
39
39
  data = {};
40
+ constructor() {
41
+ this.loadData();
42
+ }
40
43
  getData() {
41
44
  return this.data;
42
45
  }
43
46
  setData(newData) {
44
47
  this.data = (0, import_es_toolkit.toMerged)(this.data, newData);
45
48
  }
46
- async loadData() {
49
+ loadData() {
47
50
  try {
48
- await fs.access(import_constants.MPACK_DATA_DIR, fs.constants.R_OK | fs.constants.W_OK);
51
+ fs.accessSync(import_constants.MPACK_DATA_DIR, fs.constants.R_OK | fs.constants.W_OK);
49
52
  } catch {
50
- await fs.mkdir(import_constants.MPACK_DATA_DIR, { recursive: true });
53
+ fs.mkdirSync(import_constants.MPACK_DATA_DIR, { recursive: true });
51
54
  }
52
55
  try {
53
- this.data = JSON.parse(await fs.readFile(path.join(import_constants.MPACK_DATA_DIR, ".mpack"), "utf-8"));
56
+ this.data = JSON.parse(fs.readFileSync(path.join(import_constants.MPACK_DATA_DIR, ".mpack"), "utf-8"));
54
57
  } catch {
55
58
  }
56
59
  }
57
60
  async saveData() {
58
61
  try {
59
- await fs.writeFile(path.join(import_constants.MPACK_DATA_DIR, ".mpack"), JSON.stringify(this.data, null, 2), "utf-8");
62
+ await fs.promises.writeFile(path.join(import_constants.MPACK_DATA_DIR, ".mpack"), JSON.stringify(this.data, null, 2), "utf-8");
60
63
  } catch {
61
64
  }
62
65
  }
@@ -25,7 +25,20 @@ var import_md5 = require("./md5");
25
25
  var import_constants = require("../constants");
26
26
  function getId(bundleConfig) {
27
27
  return (0, import_md5.md5)(
28
- JSON.stringify([import_constants.VERSION, bundleConfig.rootDir, bundleConfig.dev, bundleConfig.buildConfig])
28
+ JSON.stringify([
29
+ import_constants.VERSION,
30
+ bundleConfig.rootDir,
31
+ bundleConfig.dev,
32
+ bundleConfig.buildConfig.resolver,
33
+ bundleConfig.buildConfig.transformer,
34
+ bundleConfig.buildConfig.platform,
35
+ bundleConfig.buildConfig.babel,
36
+ bundleConfig.buildConfig.swc,
37
+ bundleConfig.buildConfig.esbuild?.loader,
38
+ bundleConfig.buildConfig.esbuild?.resolveExtensions,
39
+ bundleConfig.buildConfig.esbuild?.mainFields,
40
+ bundleConfig.buildConfig.esbuild?.conditions
41
+ ])
29
42
  );
30
43
  }
31
44
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1 @@
1
+ export declare function printErrors(errors: PromiseRejectedResult[]): void;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var printErrors_exports = {};
20
+ __export(printErrors_exports, {
21
+ printErrors: () => printErrors
22
+ });
23
+ module.exports = __toCommonJS(printErrors_exports);
24
+ function printErrors(errors) {
25
+ for (const error of errors) {
26
+ console.error(error.reason);
27
+ }
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ printErrors
32
+ });
@@ -7,3 +7,4 @@ export interface BuildStatusProgressBar {
7
7
  remove: () => void;
8
8
  }
9
9
  export declare function createProgressBar(label: string): BuildStatusProgressBar;
10
+ export declare function cleanup(): void;
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var progressBar_exports = {};
30
30
  __export(progressBar_exports, {
31
+ cleanup: () => cleanup,
31
32
  createProgressBar: () => createProgressBar
32
33
  });
33
34
  module.exports = __toCommonJS(progressBar_exports);
@@ -91,7 +92,11 @@ function createProgressBar(label) {
91
92
  }
92
93
  };
93
94
  }
95
+ function cleanup() {
96
+ Frogress.removeAll();
97
+ }
94
98
  // Annotate the CommonJS export names for ESM import in node:
95
99
  0 && (module.exports = {
100
+ cleanup,
96
101
  createProgressBar
97
102
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@granite-js/mpack",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "A bundler for Granite apps",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -83,9 +83,9 @@
83
83
  "@babel/traverse": "^7.14.0",
84
84
  "@babel/types": "^7.0.0",
85
85
  "@fastify/static": "7.0.1",
86
- "@granite-js/devtools-frontend": "0.1.16",
87
- "@granite-js/plugin-core": "0.1.16",
88
- "@granite-js/utils": "0.1.16",
86
+ "@granite-js/devtools-frontend": "0.1.18",
87
+ "@granite-js/plugin-core": "0.1.18",
88
+ "@granite-js/utils": "0.1.18",
89
89
  "@inquirer/prompts": "^7.2.3",
90
90
  "@react-native-community/cli-plugin-metro": "11.3.7",
91
91
  "@react-native-community/cli-server-api": "11.3.7",