@shuvi/toolpack 0.0.1-rc.9 → 1.0.0-rc.10
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/lib/babel/plugins/auto-css-modules.js +1 -1
- package/lib/babel/plugins/{loadable-plugin.d.ts → dynamic-plugin.d.ts} +1 -1
- package/lib/babel/plugins/{loadable-plugin.js → dynamic-plugin.js} +9 -9
- package/lib/babel/plugins/optimize-hook-destructuring.d.ts +1 -1
- package/lib/babel/plugins/optimize-hook-destructuring.js +4 -4
- package/lib/babel/preset.js +25 -5
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +5 -1
- package/lib/utils/bundle-require.d.ts +33 -0
- package/lib/utils/bundle-require.js +143 -0
- package/lib/utils/forkTsCheckerWebpackPlugin.js +2 -1
- package/lib/utils/formatWebpackMessages.d.ts +18 -4
- package/lib/utils/formatWebpackMessages.js +17 -14
- package/lib/webpack/config/base.d.ts +17 -4
- package/lib/webpack/config/base.js +144 -99
- package/lib/webpack/config/browser.d.ts +3 -4
- package/lib/webpack/config/browser.js +132 -56
- package/lib/webpack/config/index.js +18 -7
- package/lib/webpack/config/node.d.ts +3 -4
- package/lib/webpack/config/node.js +21 -28
- package/lib/webpack/config/parts/external.d.ts +3 -2
- package/lib/webpack/config/parts/external.js +16 -10
- package/lib/webpack/config/parts/helpers.d.ts +3 -1
- package/lib/webpack/config/parts/helpers.js +14 -1
- package/lib/webpack/config/parts/resolve.js +1 -0
- package/lib/webpack/config/parts/style.d.ts +5 -2
- package/lib/webpack/config/parts/style.js +125 -60
- package/lib/webpack/dynamic-dll/bundler/index.d.ts +22 -0
- package/lib/webpack/dynamic-dll/bundler/index.js +211 -0
- package/lib/webpack/dynamic-dll/bundler/webpack-config.d.ts +16 -0
- package/lib/webpack/dynamic-dll/bundler/webpack-config.js +116 -0
- package/lib/webpack/dynamic-dll/constants.d.ts +6 -0
- package/lib/webpack/dynamic-dll/constants.js +9 -0
- package/lib/webpack/dynamic-dll/dep/getCJSExports.d.ts +3 -0
- package/lib/webpack/dynamic-dll/dep/getCJSExports.js +58 -0
- package/lib/webpack/dynamic-dll/dep/getExposeFromContent.d.ts +1 -0
- package/lib/webpack/dynamic-dll/dep/getExposeFromContent.js +80 -0
- package/lib/webpack/dynamic-dll/dep/getModuleExports.d.ts +7 -0
- package/lib/webpack/dynamic-dll/dep/getModuleExports.js +46 -0
- package/lib/webpack/dynamic-dll/dep/index.d.ts +13 -0
- package/lib/webpack/dynamic-dll/dep/index.js +43 -0
- package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.d.ts +1 -0
- package/lib/webpack/dynamic-dll/helper/check-not-in-node-modules.js +15 -0
- package/lib/webpack/dynamic-dll/index.d.ts +35 -0
- package/lib/webpack/dynamic-dll/index.js +198 -0
- package/lib/webpack/dynamic-dll/metadata.d.ts +13 -0
- package/lib/webpack/dynamic-dll/metadata.js +62 -0
- package/lib/webpack/dynamic-dll/moduleCollector.d.ts +28 -0
- package/lib/webpack/dynamic-dll/moduleCollector.js +64 -0
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.d.ts +24 -0
- package/lib/webpack/dynamic-dll/plugin/dynamic-dll-plugin.js +70 -0
- package/lib/webpack/dynamic-dll/utils.d.ts +6 -0
- package/lib/webpack/dynamic-dll/utils.js +29 -0
- package/lib/webpack/index.d.ts +15 -0
- package/lib/webpack/index.js +110 -0
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.d.ts +11 -0
- package/lib/webpack/loaders/parcel-css-loader/CssSyntaxError.js +40 -0
- package/lib/webpack/loaders/parcel-css-loader/index.d.ts +4 -0
- package/lib/webpack/loaders/parcel-css-loader/index.js +369 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/api.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/api.js +85 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/getUrl.js +23 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/noSourceMaps.js +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.d.ts +2 -0
- package/lib/webpack/loaders/parcel-css-loader/runtime/sourceMaps.js +16 -0
- package/lib/webpack/loaders/parcel-css-loader/utils.d.ts +28 -0
- package/lib/webpack/loaders/parcel-css-loader/utils.js +869 -0
- package/lib/webpack/loaders/route-component-loader.js +25 -5
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.d.ts +94 -0
- package/lib/webpack/loaders/shuvi-swc-loader/getLoaderSWCOptions.js +162 -0
- package/lib/webpack/loaders/shuvi-swc-loader/index.d.ts +2 -0
- package/lib/webpack/loaders/shuvi-swc-loader/index.js +119 -0
- package/lib/webpack/plugins/build-manifest-plugin.js +44 -23
- package/lib/webpack/plugins/dynamic-public-path-plugin.d.ts +9 -0
- package/lib/webpack/plugins/dynamic-public-path-plugin.js +50 -0
- package/lib/webpack/plugins/fix-watching-plugin.d.ts +4 -0
- package/lib/webpack/plugins/fix-watching-plugin.js +23 -0
- package/lib/webpack/plugins/jsconfig-paths-plugin.d.ts +44 -0
- package/lib/webpack/plugins/jsconfig-paths-plugin.js +228 -0
- package/lib/webpack/plugins/module-replace-plugin/index.js +5 -1
- package/lib/webpack/plugins/module-replace-plugin/plugin.d.ts +7 -6
- package/lib/webpack/plugins/module-replace-plugin/plugin.js +56 -33
- package/lib/webpack/plugins/module-replace-plugin/stub-loader.js +47 -7
- package/lib/webpack/plugins/require-cache-hot-reloader-plugin.js +9 -8
- package/lib/webpack/plugins/support-ts-extension-resolver-plugin.d.ts +4 -0
- package/lib/webpack/plugins/support-ts-extension-resolver-plugin.js +23 -0
- package/lib/webpack/types.d.ts +40 -0
- package/lib/webpack/types.js +2 -0
- package/package.json +46 -40
- package/lib/utils/emptyComponent.d.ts +0 -1
- package/lib/utils/emptyComponent.js +0 -7
- package/lib/utils/errorOverlayMiddleware.d.ts +0 -1
- package/lib/utils/errorOverlayMiddleware.js +0 -21
- package/lib/utils/hotDevClient/eventsource.d.ts +0 -1
- package/lib/utils/hotDevClient/eventsource.js +0 -63
- package/lib/utils/hotDevClient/index.d.ts +0 -4
- package/lib/utils/hotDevClient/index.js +0 -289
- package/lib/utils/verifyTypeScriptSetup.d.ts +0 -5
- package/lib/utils/verifyTypeScriptSetup.js +0 -229
- package/lib/webpack/loaders/export-global-loader.d.ts +0 -7
- package/lib/webpack/loaders/export-global-loader.js +0 -26
|
@@ -9,7 +9,7 @@ function default_1() {
|
|
|
9
9
|
visitor: {
|
|
10
10
|
ImportDeclaration(path, { opts }) {
|
|
11
11
|
const { specifiers, source, source: { value }, } = path.node;
|
|
12
|
-
if (specifiers.length && CSS_EXTNAMES.includes(path_1.extname(value))) {
|
|
12
|
+
if (specifiers.length && CSS_EXTNAMES.includes((0, path_1.extname)(value))) {
|
|
13
13
|
if (value.indexOf('?') >= 0) {
|
|
14
14
|
source.value = `${value}&${opts.flag || 'cssmodules'}`;
|
|
15
15
|
}
|
|
@@ -19,6 +19,6 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
19
19
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR
|
|
20
20
|
*/
|
|
21
21
|
import { PluginObj, types as BabelTypes } from '@babel/core';
|
|
22
|
-
export default function ({ types: t
|
|
22
|
+
export default function ({ types: t }: {
|
|
23
23
|
types: typeof BabelTypes;
|
|
24
24
|
}): PluginObj;
|
|
@@ -23,14 +23,14 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWAR
|
|
|
23
23
|
// This file is https://github.com/jamiebuilds/react-loadable/blob/master/src/babel.js
|
|
24
24
|
// Modified to also look for `shuvi/dynamic`
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
function default_1({ types: t
|
|
26
|
+
function default_1({ types: t }) {
|
|
27
27
|
return {
|
|
28
28
|
visitor: {
|
|
29
29
|
ImportDeclaration(path) {
|
|
30
30
|
let source = path.node.source.value;
|
|
31
|
-
if (source !== '@shuvi/
|
|
31
|
+
if (source !== '@shuvi/runtime')
|
|
32
32
|
return;
|
|
33
|
-
let dynamicSpecifier = path.get('specifiers').find(
|
|
33
|
+
let dynamicSpecifier = path.get('specifiers').find(specifier => {
|
|
34
34
|
return specifier.node.imported.name === 'dynamic';
|
|
35
35
|
});
|
|
36
36
|
if (!dynamicSpecifier)
|
|
@@ -40,7 +40,7 @@ function default_1({ types: t, }) {
|
|
|
40
40
|
if (!binding) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
43
|
-
binding.referencePaths.forEach(
|
|
43
|
+
binding.referencePaths.forEach(refPath => {
|
|
44
44
|
const callExpression = refPath.parentPath;
|
|
45
45
|
if (!callExpression.isCallExpression())
|
|
46
46
|
return;
|
|
@@ -68,7 +68,7 @@ function default_1({ types: t, }) {
|
|
|
68
68
|
return;
|
|
69
69
|
let properties = options.get('properties');
|
|
70
70
|
let propertiesMap = {};
|
|
71
|
-
properties.forEach(
|
|
71
|
+
properties.forEach(property => {
|
|
72
72
|
const key = property.get('key');
|
|
73
73
|
propertiesMap[key.node.name] = property;
|
|
74
74
|
});
|
|
@@ -89,17 +89,17 @@ function default_1({ types: t, }) {
|
|
|
89
89
|
return;
|
|
90
90
|
const node = args[0].node;
|
|
91
91
|
dynamicImports.push(node);
|
|
92
|
-
}
|
|
92
|
+
}
|
|
93
93
|
});
|
|
94
94
|
if (!dynamicImports.length)
|
|
95
95
|
return;
|
|
96
|
-
options.node.properties.push(t.objectProperty(t.identifier('webpack'), t.arrowFunctionExpression([], t.arrayExpression(dynamicImports.map(
|
|
96
|
+
options.node.properties.push(t.objectProperty(t.identifier('webpack'), t.arrowFunctionExpression([], t.arrayExpression(dynamicImports.map(dynamicImport => {
|
|
97
97
|
return t.callExpression(t.memberExpression(t.identifier('require'), t.identifier('resolveWeak')), [dynamicImport]);
|
|
98
98
|
})))));
|
|
99
99
|
options.node.properties.push(t.objectProperty(t.identifier('modules'), t.arrayExpression(dynamicImports)));
|
|
100
100
|
});
|
|
101
|
-
}
|
|
102
|
-
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
105
|
exports.default = default_1;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const isHook = /^use[A-Z]/;
|
|
7
7
|
// matches only built-in hooks provided by React et al
|
|
8
8
|
const isBuiltInHook = /^use(Callback|Context|DebugValue|Effect|ImperativeHandle|LayoutEffect|Memo|Reducer|Ref|State)$/;
|
|
9
|
-
function default_1({ types: t
|
|
9
|
+
function default_1({ types: t }) {
|
|
10
10
|
const visitor = {
|
|
11
11
|
CallExpression(path, state) {
|
|
12
12
|
const onlyBuiltIns = state.opts.onlyBuiltIns;
|
|
@@ -44,7 +44,7 @@ function default_1({ types: t, }) {
|
|
|
44
44
|
}
|
|
45
45
|
return patterns.concat(t.objectProperty(t.numericLiteral(i), element));
|
|
46
46
|
}, []));
|
|
47
|
-
}
|
|
47
|
+
}
|
|
48
48
|
};
|
|
49
49
|
return {
|
|
50
50
|
name: 'optimize-hook-destructuring',
|
|
@@ -52,8 +52,8 @@ function default_1({ types: t, }) {
|
|
|
52
52
|
// this is a workaround to run before preset-env destroys destructured assignments
|
|
53
53
|
Program(path, state) {
|
|
54
54
|
path.traverse(visitor, state);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
exports.default = default_1;
|
package/lib/babel/preset.js
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
4
24
|
};
|
|
5
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
26
|
+
const path = __importStar(require("path"));
|
|
7
27
|
const env = process.env.NODE_ENV;
|
|
8
28
|
const isProduction = env === 'production';
|
|
9
29
|
const isDevelopment = env === 'development';
|
|
@@ -69,7 +89,7 @@ exports.default = (api, options = {}) => {
|
|
|
69
89
|
}
|
|
70
90
|
],
|
|
71
91
|
require('@babel/plugin-syntax-dynamic-import'),
|
|
72
|
-
require('./plugins/
|
|
92
|
+
require('./plugins/dynamic-plugin'),
|
|
73
93
|
require('@babel/plugin-proposal-class-properties'),
|
|
74
94
|
[
|
|
75
95
|
require('@babel/plugin-proposal-object-rest-spread'),
|
|
@@ -83,7 +103,7 @@ exports.default = (api, options = {}) => {
|
|
|
83
103
|
// Undocumented option that lets us encapsulate our runtime, ensuring
|
|
84
104
|
// the correct version is used
|
|
85
105
|
// https://github.com/babel/babel/blob/090c364a90fe73d36a30707fc612ce037bdbbb24/packages/babel-plugin-transform-runtime/src/index.js#L35-L42
|
|
86
|
-
absoluteRuntime:
|
|
106
|
+
absoluteRuntime: path.dirname(require.resolve('@babel/runtime/package.json')) }, options['transform-runtime'])
|
|
87
107
|
],
|
|
88
108
|
isProduction && [
|
|
89
109
|
require('babel-plugin-transform-react-remove-prop-types'),
|
package/lib/constants.d.ts
CHANGED
package/lib/constants.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AppSourceRegexs =
|
|
3
|
+
exports.CommonChunkFilename = exports.AppSourceRegexs = void 0;
|
|
4
|
+
exports.AppSourceRegexs = [
|
|
5
|
+
/([/\\]shuvi-app[/\\])|([/\\]\.shuvi[/\\])/
|
|
6
|
+
];
|
|
7
|
+
exports.CommonChunkFilename = 'static/common/[name].js';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BuildOptions, Plugin as EsbuildPlugin } from 'esbuild';
|
|
2
|
+
export declare const PATH_SEG_RE: RegExp;
|
|
3
|
+
export declare const JS_EXT_RE: RegExp;
|
|
4
|
+
export declare type GetOutputFile = (filepath: string) => string;
|
|
5
|
+
export interface Options {
|
|
6
|
+
cwd?: string;
|
|
7
|
+
/**
|
|
8
|
+
* esbuild options
|
|
9
|
+
*/
|
|
10
|
+
esbuildOptions?: BuildOptions;
|
|
11
|
+
/**
|
|
12
|
+
* Get the path to the output file
|
|
13
|
+
* By default we simply replace the extension with `.bundled.js`
|
|
14
|
+
*/
|
|
15
|
+
getOutputFile?: GetOutputFile;
|
|
16
|
+
/** External packages */
|
|
17
|
+
external?: (string | RegExp)[];
|
|
18
|
+
/**
|
|
19
|
+
* Preserve compiled temporary file for debugging
|
|
20
|
+
* Default to `process.env.BUNDLE_REQUIRE_PRESERVE`
|
|
21
|
+
*/
|
|
22
|
+
preserveTemporaryFile?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare const match: (id: string, patterns?: (string | RegExp)[]) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* An esbuild plugin to mark node_modules as external
|
|
27
|
+
*/
|
|
28
|
+
export declare const externalPlugin: ({ external, notExternal }?: {
|
|
29
|
+
external?: (string | RegExp)[] | undefined;
|
|
30
|
+
notExternal?: (string | RegExp)[] | undefined;
|
|
31
|
+
}) => EsbuildPlugin;
|
|
32
|
+
export declare const replaceDirnamePlugin: () => EsbuildPlugin;
|
|
33
|
+
export declare function bundleRequire(filepath: string, options?: Options): Promise<any>;
|
|
@@ -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
|
|
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,5 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
interface StatsError {
|
|
8
|
+
moduleName?: string;
|
|
9
|
+
file?: string;
|
|
10
|
+
message?: string;
|
|
11
|
+
}
|
|
12
|
+
declare function formatWebpackMessages(json: {
|
|
13
|
+
warnings?: StatsError[];
|
|
14
|
+
errors?: StatsError[];
|
|
15
|
+
}): {
|
|
16
|
+
errors: string[];
|
|
17
|
+
warnings: string[];
|
|
5
18
|
};
|
|
19
|
+
export default formatWebpackMessages;
|
|
@@ -1,21 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
3
4
|
*
|
|
4
5
|
* This source code is licensed under the MIT license found in the
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const chalk_1 = __importDefault(require("@shuvi/utils/lib/chalk"));
|
|
9
13
|
const friendlySyntaxErrorLabel = 'Syntax error:';
|
|
10
14
|
function isLikelyASyntaxError(message) {
|
|
11
15
|
return message.indexOf(friendlySyntaxErrorLabel) !== -1;
|
|
12
16
|
}
|
|
13
17
|
// Cleans up webpack error messages.
|
|
14
|
-
function formatMessage(
|
|
15
|
-
message =
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
message.message;
|
|
18
|
+
function formatMessage(stats, isError) {
|
|
19
|
+
let message = (stats.moduleName ? stats.moduleName + '\n' : '') +
|
|
20
|
+
(stats.file ? stats.file + '\n' : '') +
|
|
21
|
+
stats.message;
|
|
19
22
|
let lines = message.split('\n');
|
|
20
23
|
// Strip Webpack-added headers off errors/warnings
|
|
21
24
|
// https://github.com/webpack/webpack/blob/master/lib/ModuleError.js
|
|
@@ -54,12 +57,12 @@ function formatMessage(message, isError) {
|
|
|
54
57
|
];
|
|
55
58
|
}
|
|
56
59
|
// Add helpful message for users trying to use Sass for the first time
|
|
57
|
-
if (lines[1] && lines[1].match(/Cannot find module.+
|
|
58
|
-
lines[1] = 'To import Sass files, you first need to install
|
|
60
|
+
if (lines[1] && lines[1].match(/Cannot find module.+sass/)) {
|
|
61
|
+
lines[1] = 'To import Sass files, you first need to install sass.\n';
|
|
59
62
|
lines[1] +=
|
|
60
|
-
'Run `npm install
|
|
63
|
+
'Run `npm install sass` or `yarn add sass` inside your workspace.';
|
|
61
64
|
}
|
|
62
|
-
lines[0] =
|
|
65
|
+
lines[0] = chalk_1.default.inverse(lines[0]);
|
|
63
66
|
message = lines.join('\n');
|
|
64
67
|
// Internal stacks are generally useless so we strip them... with the
|
|
65
68
|
// exception of stacks containing `webpack:` because they're normally
|
|
@@ -75,10 +78,10 @@ function formatMessage(message, isError) {
|
|
|
75
78
|
return message.trim();
|
|
76
79
|
}
|
|
77
80
|
function formatWebpackMessages(json) {
|
|
78
|
-
const formattedErrors = json.errors.map(function (message) {
|
|
81
|
+
const formattedErrors = (json.errors || []).map(function (message) {
|
|
79
82
|
return formatMessage(message, true);
|
|
80
83
|
});
|
|
81
|
-
const formattedWarnings = json.warnings.map(function (message) {
|
|
84
|
+
const formattedWarnings = (json.warnings || []).map(function (message) {
|
|
82
85
|
return formatMessage(message, false);
|
|
83
86
|
});
|
|
84
87
|
const result = { errors: formattedErrors, warnings: formattedWarnings };
|
|
@@ -88,4 +91,4 @@ function formatWebpackMessages(json) {
|
|
|
88
91
|
}
|
|
89
92
|
return result;
|
|
90
93
|
}
|
|
91
|
-
|
|
94
|
+
exports.default = formatWebpackMessages;
|
|
@@ -1,15 +1,28 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
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
|
};
|
|
24
|
+
experimental?: Record<string, any>;
|
|
25
|
+
compiler?: Record<string, any>;
|
|
13
26
|
}
|
|
14
27
|
export { WebpackChain };
|
|
15
|
-
export declare function baseWebpackChain({ dev, projectRoot,
|
|
28
|
+
export declare function baseWebpackChain({ dev, outputDir, parcelCss, experimental, compiler, projectRoot, include, typescript, name, buildManifestFilename, publicPath, env, cacheDir }: BaseOptions): WebpackChain;
|