@shuvi/toolpack 0.0.1-rc.8 → 1.0.0-rc.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.
Files changed (152) hide show
  1. package/lib/babel/plugins/auto-css-modules.js +1 -1
  2. package/lib/babel/plugins/loadable-plugin.js +1 -1
  3. package/lib/babel/plugins/optimize-hook-destructuring.d.ts +1 -1
  4. package/lib/babel/plugins/optimize-hook-destructuring.js +4 -4
  5. package/lib/babel/preset.js +24 -4
  6. package/lib/constants.js +4 -1
  7. package/lib/swc/tests/fixture/auto-css-module/no-flag/input.d.ts +1 -0
  8. package/lib/swc/tests/fixture/auto-css-module/no-flag/input.js +4 -0
  9. package/lib/swc/tests/fixture/auto-css-module/no-flag/output.d.ts +1 -0
  10. package/lib/swc/tests/fixture/auto-css-module/no-flag/output.js +4 -0
  11. package/lib/swc/tests/fixture/auto-css-module/with-flag/input.d.ts +1 -0
  12. package/lib/swc/tests/fixture/auto-css-module/with-flag/input.js +2 -0
  13. package/lib/swc/tests/fixture/auto-css-module/with-flag/output.d.ts +1 -0
  14. package/lib/swc/tests/fixture/auto-css-module/with-flag/output.js +2 -0
  15. package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.d.ts +1 -0
  16. package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/input.js +5 -0
  17. package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.d.ts +1 -0
  18. package/lib/swc/tests/fixture/shuvi-dynamic/duplicated-imports/output.js +11 -0
  19. package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.d.ts +1 -0
  20. package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/input.js +9 -0
  21. package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.d.ts +1 -0
  22. package/lib/swc/tests/fixture/shuvi-dynamic/member-with-same-name/output.js +12 -0
  23. package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.d.ts +1 -0
  24. package/lib/swc/tests/fixture/shuvi-dynamic/no-options/input.js +4 -0
  25. package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.d.ts +1 -0
  26. package/lib/swc/tests/fixture/shuvi-dynamic/no-options/output.js +7 -0
  27. package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.d.ts +1 -0
  28. package/lib/swc/tests/fixture/shuvi-dynamic/with-options/input.js +4 -0
  29. package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.d.ts +1 -0
  30. package/lib/swc/tests/fixture/shuvi-dynamic/with-options/output.js +8 -0
  31. package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.d.ts +1 -0
  32. package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/input.js +7 -0
  33. package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.d.ts +1 -0
  34. package/lib/swc/tests/fixture/shuvi-dynamic/wrapped-import/output.js +9 -0
  35. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.d.ts +1 -0
  36. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/input.js +5 -0
  37. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.d.ts +1 -0
  38. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/duplicated-imports/output.js +11 -0
  39. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.d.ts +1 -0
  40. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/input.js +9 -0
  41. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.d.ts +1 -0
  42. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/member-with-same-name/output.js +12 -0
  43. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.d.ts +1 -0
  44. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/input.js +4 -0
  45. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.d.ts +1 -0
  46. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/no-options/output.js +7 -0
  47. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.d.ts +1 -0
  48. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/input.js +4 -0
  49. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.d.ts +1 -0
  50. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/with-options/output.js +8 -0
  51. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.d.ts +1 -0
  52. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/input.js +7 -0
  53. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.d.ts +1 -0
  54. package/lib/swc/tests/fixture/shuvi-dynamic-disabled/wrapped-import/output.js +9 -0
  55. package/lib/swc/tests/full/auto-cjs/1/input.d.ts +1 -0
  56. package/lib/swc/tests/full/auto-cjs/1/input.js +8 -0
  57. package/lib/swc/tests/full/auto-cjs/1/output.d.ts +1 -0
  58. package/lib/swc/tests/full/auto-cjs/1/output.js +8 -0
  59. package/lib/utils/build-loaders.d.ts +2 -0
  60. package/lib/utils/build-loaders.js +131 -0
  61. package/lib/utils/bundle-require.d.ts +33 -0
  62. package/lib/utils/bundle-require.js +143 -0
  63. package/lib/utils/forkTsCheckerWebpackPlugin.js +2 -1
  64. package/lib/utils/formatWebpackMessages.d.ts +1 -1
  65. package/lib/utils/formatWebpackMessages.js +2 -1
  66. package/lib/utils/hotDevClient/eventsource.js +1 -0
  67. package/lib/utils/hotDevClient/index.js +102 -29
  68. package/lib/utils/load-sources.d.ts +3 -0
  69. package/lib/utils/load-sources.js +94 -0
  70. package/lib/webpack/config/base.d.ts +15 -4
  71. package/lib/webpack/config/base.js +107 -85
  72. package/lib/webpack/config/browser.d.ts +3 -4
  73. package/lib/webpack/config/browser.js +87 -34
  74. package/lib/webpack/config/index.js +18 -7
  75. package/lib/webpack/config/node.d.ts +3 -4
  76. package/lib/webpack/config/node.js +19 -26
  77. package/lib/webpack/config/parts/external.d.ts +3 -2
  78. package/lib/webpack/config/parts/external.js +16 -10
  79. package/lib/webpack/config/parts/helpers.d.ts +2 -1
  80. package/lib/webpack/config/parts/helpers.js +7 -1
  81. package/lib/webpack/config/parts/resolve.js +1 -0
  82. package/lib/webpack/config/parts/style.d.ts +5 -2
  83. package/lib/webpack/config/parts/style.js +125 -60
  84. package/lib/webpack/dynamic-dll/bundler/index.d.ts +22 -0
  85. package/lib/webpack/dynamic-dll/bundler/index.js +211 -0
  86. package/lib/webpack/dynamic-dll/bundler/webpack-config.d.ts +16 -0
  87. package/lib/webpack/dynamic-dll/bundler/webpack-config.js +116 -0
  88. package/lib/webpack/dynamic-dll/constants.d.ts +6 -0
  89. package/lib/webpack/dynamic-dll/constants.js +9 -0
  90. package/lib/webpack/dynamic-dll/dep/getCJSExports.d.ts +3 -0
  91. package/lib/webpack/dynamic-dll/dep/getCJSExports.js +58 -0
  92. package/lib/webpack/dynamic-dll/dep/getExposeFromContent.d.ts +1 -0
  93. package/lib/webpack/dynamic-dll/dep/getExposeFromContent.js +80 -0
  94. package/lib/webpack/dynamic-dll/dep/getModuleExports.d.ts +7 -0
  95. package/lib/webpack/dynamic-dll/dep/getModuleExports.js +46 -0
  96. package/lib/webpack/dynamic-dll/dep/index.d.ts +13 -0
  97. package/lib/webpack/dynamic-dll/dep/index.js +43 -0
  98. package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.d.ts +1 -0
  99. package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.js +15 -0
  100. package/lib/webpack/dynamic-dll/index.d.ts +35 -0
  101. package/lib/webpack/dynamic-dll/index.js +198 -0
  102. package/lib/webpack/dynamic-dll/metadata.d.ts +13 -0
  103. package/lib/webpack/dynamic-dll/metadata.js +62 -0
  104. package/lib/webpack/dynamic-dll/moduleCollector.d.ts +28 -0
  105. package/lib/webpack/dynamic-dll/moduleCollector.js +64 -0
  106. package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.d.ts +24 -0
  107. package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +71 -0
  108. package/lib/webpack/dynamic-dll/utils.d.ts +6 -0
  109. package/lib/webpack/dynamic-dll/utils.js +29 -0
  110. package/lib/webpack/index.d.ts +17 -0
  111. package/lib/webpack/index.js +112 -0
  112. package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +4 -0
  113. package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +39 -0
  114. package/lib/webpack/loaders/parcel-css-loader/index.d.ts +4 -0
  115. package/lib/webpack/loaders/parcel-css-loader/index.js +369 -0
  116. package/lib/webpack/loaders/parcel-css-loader/runtime/api.d.ts +2 -0
  117. package/lib/webpack/loaders/parcel-css-loader/runtime/api.js +85 -0
  118. package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.d.ts +2 -0
  119. package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.js +23 -0
  120. package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.d.ts +2 -0
  121. package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.js +2 -0
  122. package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.d.ts +2 -0
  123. package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.js +16 -0
  124. package/lib/webpack/loaders/parcel-css-loader/utils.d.ts +28 -0
  125. package/lib/webpack/loaders/parcel-css-loader/utils.js +869 -0
  126. package/lib/webpack/loaders/route-component-loader.js +25 -5
  127. package/lib/webpack/loaders/shuvi-swc-loader.d.ts +2 -0
  128. package/lib/webpack/loaders/shuvi-swc-loader.js +155 -0
  129. package/lib/webpack/plugins/build-manifest-plugin.js +44 -23
  130. package/lib/webpack/plugins/dynamic-public-path-plugin.d.ts +9 -0
  131. package/lib/webpack/plugins/dynamic-public-path-plugin.js +50 -0
  132. package/lib/webpack/plugins/jsconfig-paths-plugin.d.ts +44 -0
  133. package/lib/webpack/plugins/jsconfig-paths-plugin.js +228 -0
  134. package/lib/webpack/plugins/module-replace-plugin/index.js +5 -1
  135. package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +6 -6
  136. package/lib/webpack/plugins/module-replace-plugin/plugin.js +47 -32
  137. package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +47 -7
  138. package/lib/webpack/plugins/require-cache-hot-reloader-plugin.js +9 -8
  139. package/lib/webpack/plugins/support-ts-extension-resolver-plugin.d.ts +4 -0
  140. package/lib/webpack/plugins/support-ts-extension-resolver-plugin.js +23 -0
  141. package/lib/webpack/types.d.ts +40 -0
  142. package/lib/webpack/types.js +2 -0
  143. package/package.json +85 -44
  144. package/swc-source/native/shuvi-swc.darwin-arm64.node +0 -0
  145. package/lib/utils/emptyComponent.d.ts +0 -1
  146. package/lib/utils/emptyComponent.js +0 -7
  147. package/lib/utils/errorOverlayMiddleware.d.ts +0 -2
  148. package/lib/utils/errorOverlayMiddleware.js +0 -33
  149. package/lib/utils/verifyTypeScriptSetup.d.ts +0 -5
  150. package/lib/utils/verifyTypeScriptSetup.js +0 -229
  151. package/lib/webpack/loaders/export-global-loader.d.ts +0 -7
  152. package/lib/webpack/loaders/export-global-loader.js +0 -26
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ // modified from https://github.com/egoist/bundle-require/blob/dd96549a9b995d6a827baee022eb324fd2fac2ef/src/index.ts
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || function (mod) {
20
+ if (mod && mod.__esModule) return mod;
21
+ var result = {};
22
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
+ __setModuleDefault(result, mod);
24
+ return result;
25
+ };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.bundleRequire = exports.replaceDirnamePlugin = exports.externalPlugin = exports.match = exports.JS_EXT_RE = exports.PATH_SEG_RE = void 0;
37
+ const fs_1 = require("fs");
38
+ const path = __importStar(require("path"));
39
+ const esbuild_1 = require("esbuild");
40
+ exports.PATH_SEG_RE = /\/|\\/g;
41
+ const CACHE_DIR = path.join(process.cwd(), './node_modules/.bundle-require');
42
+ function inferLoader(ext) {
43
+ if (ext === '.mjs' || ext === '.cjs')
44
+ return 'js';
45
+ return ext.slice(1);
46
+ }
47
+ exports.JS_EXT_RE = /\.(mjs|cjs|ts|js|tsx|jsx)$/;
48
+ const defaultGetOutputFile = (filepath) => path.join(CACHE_DIR, filepath
49
+ .replace(exports.PATH_SEG_RE, '_')
50
+ .replace(exports.JS_EXT_RE, `.bundled_${Date.now()}.cjs`));
51
+ const match = (id, patterns) => {
52
+ if (!patterns)
53
+ return false;
54
+ return patterns.some(p => {
55
+ if (p instanceof RegExp) {
56
+ return p.test(id);
57
+ }
58
+ return id === p || id.startsWith(p + '/');
59
+ });
60
+ };
61
+ exports.match = match;
62
+ /**
63
+ * An esbuild plugin to mark node_modules as external
64
+ */
65
+ const externalPlugin = ({ external, notExternal } = {}) => {
66
+ return {
67
+ name: 'bundle-require:external',
68
+ setup(ctx) {
69
+ ctx.onResolve({ filter: /.*/ }, (args) => __awaiter(this, void 0, void 0, function* () {
70
+ if (args.path[0] === '.' || path.isAbsolute(args.path)) {
71
+ // Fallback to default
72
+ return;
73
+ }
74
+ if ((0, exports.match)(args.path, external)) {
75
+ return {
76
+ external: true
77
+ };
78
+ }
79
+ if ((0, exports.match)(args.path, notExternal)) {
80
+ // Should be resolved by esbuild
81
+ return;
82
+ }
83
+ // Most like importing from node_modules, mark external
84
+ return {
85
+ external: true
86
+ };
87
+ }));
88
+ }
89
+ };
90
+ };
91
+ exports.externalPlugin = externalPlugin;
92
+ const replaceDirnamePlugin = () => {
93
+ return {
94
+ name: 'bundle-require:replace-path',
95
+ setup(ctx) {
96
+ ctx.onLoad({ filter: exports.JS_EXT_RE }, (args) => __awaiter(this, void 0, void 0, function* () {
97
+ const contents = yield fs_1.promises.readFile(args.path, 'utf-8');
98
+ return {
99
+ contents: contents
100
+ .replace(/[^"'\\]\b__filename\b[^"'\\]/g, match => match.replace('__filename', JSON.stringify(args.path)))
101
+ .replace(/[^"'\\]\b__dirname\b[^"'\\]/g, match => match.replace('__dirname', JSON.stringify(path.dirname(args.path))))
102
+ .replace(/[^"'\\]\bimport\.meta\.url\b[^"'\\]/g, match => match.replace('import.meta.url', JSON.stringify(`file://${args.path}`))),
103
+ loader: inferLoader(path.extname(args.path))
104
+ };
105
+ }));
106
+ }
107
+ };
108
+ };
109
+ exports.replaceDirnamePlugin = replaceDirnamePlugin;
110
+ function bundleRequire(filepath, options = {}) {
111
+ var _a, _b;
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ if (!exports.JS_EXT_RE.test(filepath)) {
114
+ throw new Error(`${filepath} is not a valid JS file`);
115
+ }
116
+ const cwd = options.cwd || process.cwd();
117
+ const getOutputFile = options.getOutputFile || defaultGetOutputFile;
118
+ const outfile = getOutputFile(filepath);
119
+ const preserveTemporaryFile = (_a = options.preserveTemporaryFile) !== null && _a !== void 0 ? _a : !!process.env.BUNDLE_REQUIRE_PRESERVE;
120
+ const extractResult = (result) => __awaiter(this, void 0, void 0, function* () {
121
+ let mod;
122
+ try {
123
+ mod = yield require(outfile);
124
+ }
125
+ finally {
126
+ if (!preserveTemporaryFile) {
127
+ // Remove the outfile after executed
128
+ yield fs_1.promises.unlink(outfile);
129
+ }
130
+ }
131
+ return mod;
132
+ });
133
+ const result = yield (0, esbuild_1.build)(Object.assign(Object.assign({}, options.esbuildOptions), { entryPoints: [filepath], absWorkingDir: cwd, outfile, format: 'cjs', platform: 'node', sourcemap: 'inline', bundle: true, metafile: true, write: true, watch: false, plugins: [
134
+ ...(((_b = options.esbuildOptions) === null || _b === void 0 ? void 0 : _b.plugins) || []),
135
+ (0, exports.externalPlugin)({
136
+ external: options.external
137
+ }),
138
+ (0, exports.replaceDirnamePlugin)()
139
+ ] }));
140
+ return extractResult(result);
141
+ });
142
+ }
143
+ exports.bundleRequire = bundleRequire;
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createCodeFrameFormatter = void 0;
6
7
  const fork_ts_checker_webpack_plugin_1 = __importDefault(require("fork-ts-checker-webpack-plugin"));
7
8
  var CodeFrameFormatter_1 = require("fork-ts-checker-webpack-plugin/lib/formatter/CodeFrameFormatter");
8
- exports.createCodeFrameFormatter = CodeFrameFormatter_1.createCodeFrameFormatter;
9
+ Object.defineProperty(exports, "createCodeFrameFormatter", { enumerable: true, get: function () { return CodeFrameFormatter_1.createCodeFrameFormatter; } });
9
10
  exports.default = fork_ts_checker_webpack_plugin_1.default;
@@ -1,4 +1,4 @@
1
- export = formatWebpackMessages;
1
+ export default formatWebpackMessages;
2
2
  declare function formatWebpackMessages(json: any): {
3
3
  errors: any;
4
4
  warnings: any;
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
8
9
  const chalk = require('@shuvi/utils/lib/chalk').default;
9
10
  const friendlySyntaxErrorLabel = 'Syntax error:';
10
11
  function isLikelyASyntaxError(message) {
@@ -88,4 +89,4 @@ function formatWebpackMessages(json) {
88
89
  }
89
90
  return result;
90
91
  }
91
- module.exports = formatWebpackMessages;
92
+ exports.default = formatWebpackMessages;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEventSourceWrapper = void 0;
3
4
  const eventCallbacks = [];
4
5
  function EventSourceWrapper(options) {
5
6
  var source;
@@ -25,6 +25,29 @@ SOFTWARE.
25
25
  */
26
26
  // This file is based on https://github.com/facebook/create-react-app/blob/v1.1.4/packages/react-dev-utils/webpackHotDevClient.js
27
27
  // It's been edited to rely on webpack-hot-middleware.
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || function (mod) {
45
+ if (mod && mod.__esModule) return mod;
46
+ var result = {};
47
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
48
+ __setModuleDefault(result, mod);
49
+ return result;
50
+ };
28
51
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
52
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
53
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -34,13 +57,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
57
  step((generator = generator.apply(thisArg, _arguments || [])).next());
35
58
  });
36
59
  };
37
- var __importStar = (this && this.__importStar) || function (mod) {
38
- if (mod && mod.__esModule) return mod;
39
- var result = {};
40
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
41
- result["default"] = mod;
42
- return result;
43
- };
44
60
  var __importDefault = (this && this.__importDefault) || function (mod) {
45
61
  return (mod && mod.__esModule) ? mod : { "default": mod };
46
62
  };
@@ -91,7 +107,7 @@ function connect(options) {
91
107
  ErrorOverlay.stopReportingRuntimeErrors();
92
108
  });
93
109
  }
94
- eventsource_1.getEventSourceWrapper(options).addMessageListener(event => {
110
+ (0, eventsource_1.getEventSourceWrapper)(options).addMessageListener(event => {
95
111
  // This is the heartbeat event
96
112
  if (event.data === '\uD83D\uDC93') {
97
113
  return;
@@ -125,8 +141,9 @@ function clearOutdatedErrors() {
125
141
  }
126
142
  }
127
143
  }
128
- function afterApplyUpdate(hasUpdates) {
144
+ function afterApplyUpdate() {
129
145
  tryDismissErrorOverlay();
146
+ console.log('[Fast Refresh] Done.');
130
147
  }
131
148
  // Successful compilation.
132
149
  function handleSuccess() {
@@ -136,18 +153,21 @@ function handleSuccess() {
136
153
  hasCompileErrors = false;
137
154
  // Attempt to apply hot updates or reload.
138
155
  if (isHotUpdate) {
139
- tryApplyUpdates(function onHotUpdateSuccess(hasUpdates) {
156
+ tryApplyUpdates(function onHotUpdateSuccess() {
140
157
  // Only dismiss it when we're sure it's a hot update.
141
158
  // Otherwise it would flicker right before the reload.
142
- afterApplyUpdate(hasUpdates);
159
+ afterApplyUpdate();
143
160
  });
144
161
  }
145
162
  }
146
163
  // Compilation with warnings (e.g. ESLint).
147
164
  function handleWarnings(warnings) {
148
165
  clearOutdatedErrors();
166
+ var isHotUpdate = !isFirstCompilation;
167
+ isFirstCompilation = false;
168
+ hasCompileErrors = false;
149
169
  // Print warnings to the console.
150
- const formatted = formatWebpackMessages_1.default({
170
+ const formatted = (0, formatWebpackMessages_1.default)({
151
171
  warnings: warnings,
152
172
  errors: []
153
173
  });
@@ -158,9 +178,18 @@ function handleWarnings(warnings) {
158
178
  'You can find a complete log in the terminal.');
159
179
  break;
160
180
  }
161
- console.warn(strip_ansi_1.default(formatted.warnings[i]));
181
+ console.warn((0, strip_ansi_1.default)(formatted.warnings[i]));
162
182
  }
163
183
  }
184
+ // Attempt to apply hot updates or reload.
185
+ if (isHotUpdate) {
186
+ tryApplyUpdates(function onSuccessfulHotUpdate() {
187
+ // Only dismiss it when we're sure it's a hot update.
188
+ // Otherwise it would flicker right before the reload.
189
+ tryDismissErrorOverlay();
190
+ afterApplyUpdate();
191
+ });
192
+ }
164
193
  }
165
194
  // Compilation with errors (e.g. syntax error or missing modules).
166
195
  function handleErrors(errors) {
@@ -168,7 +197,7 @@ function handleErrors(errors) {
168
197
  isFirstCompilation = false;
169
198
  hasCompileErrors = true;
170
199
  // "Massage" webpack messages.
171
- var formatted = formatWebpackMessages_1.default({
200
+ var formatted = (0, formatWebpackMessages_1.default)({
172
201
  errors: errors,
173
202
  warnings: []
174
203
  });
@@ -177,7 +206,7 @@ function handleErrors(errors) {
177
206
  // Also log them to the console.
178
207
  if (typeof console !== 'undefined' && typeof console.error === 'function') {
179
208
  for (var i = 0; i < formatted.errors.length; i++) {
180
- console.error(strip_ansi_1.default(formatted.errors[i]));
209
+ console.error((0, strip_ansi_1.default)(formatted.errors[i]));
181
210
  }
182
211
  }
183
212
  }
@@ -196,7 +225,9 @@ function processMessage(e) {
196
225
  const obj = JSON.parse(e.data);
197
226
  switch (obj.action) {
198
227
  case 'building': {
199
- console.log('[HMR] bundle ' + (obj.name ? "'" + obj.name + "' " : '') + 'rebuilding');
228
+ console.log('[Fast Refresh] bundle ' +
229
+ (obj.name ? "'" + obj.name + "' " : '') +
230
+ 'rebuilding');
200
231
  break;
201
232
  }
202
233
  case 'built':
@@ -242,44 +273,86 @@ function isUpdateAvailable() {
242
273
  function canApplyUpdates() {
243
274
  return module.hot.status() === 'idle';
244
275
  }
276
+ function waitForReady() {
277
+ return new Promise((resolve, reject) => {
278
+ if (module.hot.status() !== 'prepare') {
279
+ reject();
280
+ }
281
+ const handler = status => {
282
+ module.hot.removeStatusHandler(handler);
283
+ if (status === 'ready') {
284
+ resolve();
285
+ }
286
+ if (status === 'abort' || status === 'fail') {
287
+ reject();
288
+ }
289
+ };
290
+ module.hot.addStatusHandler(handler);
291
+ });
292
+ }
245
293
  // Attempt to update code on the fly, fall back to a hard reload.
246
294
  function tryApplyUpdates(onHotUpdateSuccess) {
247
295
  return __awaiter(this, void 0, void 0, function* () {
248
296
  if (!module.hot) {
249
297
  // HotModuleReplacementPlugin is not in Webpack configuration.
250
298
  console.error('HotModuleReplacementPlugin is not in Webpack configuration.');
251
- // window.location.reload();
299
+ window.location.reload();
252
300
  return;
253
301
  }
254
302
  if (!isUpdateAvailable() || !canApplyUpdates()) {
255
303
  ErrorOverlay.dismissBuildError();
304
+ // HMR failed, need to refresh
305
+ const hmrStatus = module.hot.status();
306
+ if (hmrStatus === 'abort' || hmrStatus === 'fail') {
307
+ window.location.reload();
308
+ }
256
309
  return;
257
310
  }
258
311
  function handleApplyUpdates(err, updatedModules) {
259
- const needForcedReload = err || !updatedModules || hadRuntimeError;
312
+ const needForcedReload = err || hadRuntimeError;
260
313
  if (needForcedReload) {
261
- if (err) {
262
- console.warn('Error while applying updates, reloading page', err);
263
- }
264
314
  if (hadRuntimeError) {
265
- console.warn('Had runtime error previously, reloading page');
315
+ hadRuntimeError = false;
316
+ window.location.reload();
317
+ }
318
+ else {
319
+ ErrorOverlay.reportRuntimeError(err);
320
+ hadRuntimeError = true;
266
321
  }
267
- window.location.reload();
268
- return;
269
322
  }
270
- const hasUpdates = Boolean(updatedModules.length);
271
323
  if (typeof onHotUpdateSuccess === 'function') {
272
324
  // Maybe we want to do something.
273
- onHotUpdateSuccess(hasUpdates);
325
+ onHotUpdateSuccess();
274
326
  }
275
327
  if (isUpdateAvailable()) {
276
328
  // While we were updating, there was a new update! Do it again.
277
- tryApplyUpdates();
329
+ tryApplyUpdates(onHotUpdateSuccess);
278
330
  }
279
331
  }
280
- // https://webpack.github.io/docs/hot-module-replacement.html#check
281
332
  try {
282
- const updatedModules = yield module.hot.check(/* autoApply */ true);
333
+ // https://webpack.js.org/api/hot-module-replacement/#check
334
+ let updatedModules = yield module.hot.check(/* autoApply */ false);
335
+ if (!updatedModules) {
336
+ return;
337
+ }
338
+ // if there is another updating, delay the update
339
+ // multiple hotupdate occurs during import() will cause hmr error
340
+ // so we delay the adjacent hotupdates
341
+ // import() == loade module script ----> require(module)
342
+ // |
343
+ // |
344
+ // if applyUpdate happens here, require will cause a error
345
+ if (isUpdateAvailable()) {
346
+ yield new Promise(resolve => {
347
+ setTimeout(resolve, 50);
348
+ });
349
+ }
350
+ if (updatedModules) {
351
+ if (module.hot.status() !== 'ready') {
352
+ yield waitForReady();
353
+ }
354
+ updatedModules = yield module.hot.apply();
355
+ }
283
356
  handleApplyUpdates(null, updatedModules);
284
357
  }
285
358
  catch (err) {
@@ -0,0 +1,3 @@
1
+ export function minify(src: any, opts: any): Promise<any>;
2
+ export function minifySync(src: any, opts: any): any;
3
+ export function bundle(options: any): Promise<any>;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.bundle = exports.minifySync = exports.minify = void 0;
13
+ const fs = require('fs');
14
+ const { platform, arch } = require('os');
15
+ const path = require('path');
16
+ const { platformArchTriples } = require('@napi-rs/triples');
17
+ const ArchName = arch();
18
+ const PlatformName = platform();
19
+ let bindings;
20
+ let loadError;
21
+ const triples = platformArchTriples[PlatformName][ArchName];
22
+ for (const triple of triples) {
23
+ try {
24
+ const swcSource = path.join(__dirname, '../../swc-source');
25
+ const localFilePath = path.join(swcSource, `native/shuvi-swc.${triple.platformArchABI}.node`);
26
+ if (fs.existsSync(localFilePath)) {
27
+ console.log('Using locally built binary of shuvi-swc');
28
+ try {
29
+ bindings = require(localFilePath);
30
+ }
31
+ catch (e) {
32
+ if ((e === null || e === void 0 ? void 0 : e.code) !== 'MODULE_NOT_FOUND') {
33
+ loadError = e;
34
+ }
35
+ }
36
+ break;
37
+ }
38
+ break;
39
+ }
40
+ catch (e) {
41
+ bindings = require(`@shuvi/swc-${triple.platformArchABI}`);
42
+ }
43
+ }
44
+ if (!bindings) {
45
+ if (loadError) {
46
+ console.error(loadError);
47
+ }
48
+ console.error(`Failed to load SWC binary`);
49
+ process.exit(1);
50
+ }
51
+ else {
52
+ loadError = null;
53
+ }
54
+ function transform(src, options) {
55
+ var _a, _b;
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const isModule = typeof src !== 'string' && !Buffer.isBuffer(src);
58
+ options = options || {};
59
+ if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
60
+ options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
61
+ }
62
+ return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
63
+ });
64
+ }
65
+ function transformSync(src, options) {
66
+ var _a, _b;
67
+ const isModule = typeof src !== 'string' && !Buffer.isBuffer(src);
68
+ options = options || {};
69
+ if ((_a = options === null || options === void 0 ? void 0 : options.jsc) === null || _a === void 0 ? void 0 : _a.parser) {
70
+ options.jsc.parser.syntax = (_b = options.jsc.parser.syntax) !== null && _b !== void 0 ? _b : 'ecmascript';
71
+ }
72
+ return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options));
73
+ }
74
+ function toBuffer(t) {
75
+ return Buffer.from(JSON.stringify(t));
76
+ }
77
+ function minify(src, opts) {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ return bindings.minify(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
80
+ });
81
+ }
82
+ exports.minify = minify;
83
+ function minifySync(src, opts) {
84
+ return bindings.minifySync(toBuffer(src), toBuffer(opts !== null && opts !== void 0 ? opts : {}));
85
+ }
86
+ exports.minifySync = minifySync;
87
+ function bundle(options) {
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ return bindings.bundle(toBuffer(options));
90
+ });
91
+ }
92
+ exports.bundle = bundle;
93
+ module.exports.transform = transform;
94
+ module.exports.transformSync = transformSync;
@@ -1,15 +1,26 @@
1
1
  import WebpackChain from 'webpack-chain';
2
+ declare type TsCompilerOptions = import('typescript').CompilerOptions;
2
3
  export interface BaseOptions {
3
4
  dev: boolean;
5
+ parcelCss: boolean;
6
+ name: string;
4
7
  projectRoot: string;
5
- srcDirs: string[];
6
- mediaFilename: string;
8
+ outputDir: string;
9
+ cacheDir: string;
10
+ include: string[];
11
+ typescript?: {
12
+ useTypeScript: boolean;
13
+ typeScriptPath?: string;
14
+ tsConfigPath?: string;
15
+ tsCompilerOptions?: TsCompilerOptions;
16
+ resolvedBaseUrl?: string;
17
+ };
7
18
  buildManifestFilename: string;
8
19
  target?: string;
9
20
  publicPath?: string;
10
21
  env?: {
11
- [x: string]: string;
22
+ [x: string]: string | undefined;
12
23
  };
13
24
  }
14
25
  export { WebpackChain };
15
- export declare function baseWebpackChain({ dev, projectRoot, srcDirs, mediaFilename, buildManifestFilename, publicPath, env }: BaseOptions): WebpackChain;
26
+ export declare function baseWebpackChain({ dev, outputDir, parcelCss, projectRoot, include, typescript, name, buildManifestFilename, publicPath, env, cacheDir }: BaseOptions): WebpackChain;