@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
|
@@ -0,0 +1,211 @@
|
|
|
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.Bundler = void 0;
|
|
13
|
+
const webpack_1 = require("webpack");
|
|
14
|
+
const fs_extra_1 = require("fs-extra");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
17
|
+
const constants_1 = require("../constants");
|
|
18
|
+
const dep_1 = require("../dep");
|
|
19
|
+
const metadata_1 = require("../metadata");
|
|
20
|
+
const utils_1 = require("../utils");
|
|
21
|
+
const webpack_config_1 = require("./webpack-config");
|
|
22
|
+
function getHash(text) {
|
|
23
|
+
return (0, crypto_1.createHash)('sha256').update(text).digest('hex').substring(0, 8);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* hash everything that can change the build result
|
|
27
|
+
*
|
|
28
|
+
* @param {BuildOptions} options
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/
|
|
31
|
+
function getMainHash(options) {
|
|
32
|
+
let content = JSON.stringify({
|
|
33
|
+
shared: options.shared
|
|
34
|
+
});
|
|
35
|
+
return getHash([utils_1.version, content].join(''));
|
|
36
|
+
}
|
|
37
|
+
function getBuildHash(hash, snapshot) {
|
|
38
|
+
return getHash(hash + JSON.stringify(snapshot));
|
|
39
|
+
}
|
|
40
|
+
function getWebpackConfig({ deps, entry, outputDir, shared, externals, esmFullSpecific }) {
|
|
41
|
+
const exposes = deps.reduce((memo, dep) => {
|
|
42
|
+
memo[`./${dep.request}`] = dep.filename;
|
|
43
|
+
return memo;
|
|
44
|
+
}, {});
|
|
45
|
+
const chain = (0, webpack_config_1.getConfig)({
|
|
46
|
+
name: constants_1.NAME,
|
|
47
|
+
entry,
|
|
48
|
+
filename: constants_1.DLL_FILENAME,
|
|
49
|
+
outputDir,
|
|
50
|
+
publicPath: constants_1.DEFAULT_PUBLIC_PATH,
|
|
51
|
+
shared,
|
|
52
|
+
externals,
|
|
53
|
+
esmFullSpecific,
|
|
54
|
+
exposes
|
|
55
|
+
});
|
|
56
|
+
return chain.toConfig();
|
|
57
|
+
}
|
|
58
|
+
function buildDeps({ deps, dir }) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
(0, fs_extra_1.mkdirpSync)(dir);
|
|
61
|
+
// expose files
|
|
62
|
+
yield Promise.all(deps.map((dep) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const content = yield dep.buildExposeContent();
|
|
64
|
+
yield (0, fs_extra_1.writeFile)(dep.filename, content, 'utf-8');
|
|
65
|
+
})));
|
|
66
|
+
// index file
|
|
67
|
+
(0, fs_extra_1.writeFileSync)((0, path_1.join)(dir, 'index.js'), 'export default "dynamicDll index.js";', 'utf-8');
|
|
68
|
+
return deps;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function webpackBuild(config) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
console.log(`[@shuvi/dll]: Bundle start`);
|
|
75
|
+
const compiler = (0, webpack_1.webpack)(config);
|
|
76
|
+
compiler.run((err, stats) => {
|
|
77
|
+
if (err || (stats === null || stats === void 0 ? void 0 : stats.hasErrors())) {
|
|
78
|
+
if (err) {
|
|
79
|
+
reject(err);
|
|
80
|
+
}
|
|
81
|
+
if (stats) {
|
|
82
|
+
const errorMsg = stats.toString('errors-only');
|
|
83
|
+
reject(new Error(errorMsg));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
resolve(stats);
|
|
88
|
+
}
|
|
89
|
+
compiler.close(() => { });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function isSnapshotSame(pre, cur) {
|
|
95
|
+
const keys = Object.keys(cur);
|
|
96
|
+
for (let index = 0; index < keys.length; index++) {
|
|
97
|
+
const id = keys[index];
|
|
98
|
+
const preItem = pre[id];
|
|
99
|
+
const nextItem = cur[id];
|
|
100
|
+
if (!preItem) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
if (preItem.version !== nextItem.version) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
class Bundler {
|
|
110
|
+
constructor() {
|
|
111
|
+
this._nextBuild = null;
|
|
112
|
+
this._completeFns = [];
|
|
113
|
+
this._isBuilding = false;
|
|
114
|
+
}
|
|
115
|
+
build(snapshot, options) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
if (this._isBuilding) {
|
|
118
|
+
this._nextBuild = snapshot;
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
let error = null;
|
|
122
|
+
this._isBuilding = true;
|
|
123
|
+
let hasBuild = false;
|
|
124
|
+
let timer = new Date().getTime();
|
|
125
|
+
try {
|
|
126
|
+
[hasBuild] = yield this._buildDll(snapshot, options);
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
error = err;
|
|
130
|
+
}
|
|
131
|
+
this._isBuilding = false;
|
|
132
|
+
if (error) {
|
|
133
|
+
console.error(`[@shuvi/dll]: Bundle Error`);
|
|
134
|
+
console.error(error);
|
|
135
|
+
}
|
|
136
|
+
this._completeFns.forEach(fn => fn(error));
|
|
137
|
+
this._completeFns = [];
|
|
138
|
+
if (hasBuild) {
|
|
139
|
+
console.log(`[@shuvi/dll]: Bundle Success, cost ${new Date().getTime() - timer}ms`);
|
|
140
|
+
timer = new Date().getTime();
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
_buildDll(snapshot, options) {
|
|
145
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
+
const { externals = {}, shared = {}, outputDir, force, esmFullSpecific = true } = options;
|
|
147
|
+
const mainHash = getMainHash(options);
|
|
148
|
+
const dllDir = (0, utils_1.getDllDir)(outputDir);
|
|
149
|
+
const preMetadata = (0, metadata_1.getMetadata)(outputDir);
|
|
150
|
+
const metadata = {
|
|
151
|
+
hash: mainHash,
|
|
152
|
+
buildHash: preMetadata.buildHash,
|
|
153
|
+
modules: snapshot
|
|
154
|
+
};
|
|
155
|
+
if (!force &&
|
|
156
|
+
preMetadata.hash === metadata.hash &&
|
|
157
|
+
isSnapshotSame(preMetadata.modules, snapshot)) {
|
|
158
|
+
return [false, preMetadata];
|
|
159
|
+
}
|
|
160
|
+
const dllPendingDir = (0, utils_1.getDllPendingDir)(outputDir);
|
|
161
|
+
// create a temporal dir to build. This avoids leaving the dll
|
|
162
|
+
// in a corrupted state if there is an error during the build
|
|
163
|
+
if ((0, fs_extra_1.existsSync)(dllPendingDir)) {
|
|
164
|
+
(0, fs_extra_1.emptyDirSync)(dllPendingDir);
|
|
165
|
+
}
|
|
166
|
+
const depsDir = (0, utils_1.getDepsDir)(dllPendingDir);
|
|
167
|
+
const deps = Object.entries(snapshot).map(([request, { version, libraryPath }]) => {
|
|
168
|
+
return new dep_1.Dep({
|
|
169
|
+
request,
|
|
170
|
+
libraryPath,
|
|
171
|
+
version,
|
|
172
|
+
outputPath: depsDir
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
yield buildDeps({
|
|
176
|
+
deps,
|
|
177
|
+
dir: depsDir
|
|
178
|
+
});
|
|
179
|
+
let timer = new Date().getTime();
|
|
180
|
+
yield webpackBuild(getWebpackConfig({
|
|
181
|
+
deps,
|
|
182
|
+
entry: (0, path_1.join)(depsDir, 'index.js'),
|
|
183
|
+
shared,
|
|
184
|
+
externals,
|
|
185
|
+
esmFullSpecific,
|
|
186
|
+
outputDir: dllPendingDir
|
|
187
|
+
}));
|
|
188
|
+
console.log(`[dll Bundle time]: ${new Date().getTime() - timer}ms`);
|
|
189
|
+
if (this._nextBuild) {
|
|
190
|
+
const param = this._nextBuild;
|
|
191
|
+
this._nextBuild = null;
|
|
192
|
+
return yield this._buildDll(param, options);
|
|
193
|
+
}
|
|
194
|
+
metadata.buildHash = getBuildHash(metadata.hash, snapshot);
|
|
195
|
+
// finish build
|
|
196
|
+
(0, metadata_1.writeMetadata)(dllPendingDir, metadata);
|
|
197
|
+
(0, fs_extra_1.removeSync)(dllDir);
|
|
198
|
+
(0, fs_extra_1.renameSync)(dllPendingDir, dllDir);
|
|
199
|
+
return [true, metadata];
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
onBuildComplete(fn) {
|
|
203
|
+
if (this._isBuilding) {
|
|
204
|
+
this._completeFns.push(fn);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
fn();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.Bundler = Bundler;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import WebpackChain from 'webpack-chain';
|
|
2
|
+
import type { Configuration } from 'webpack';
|
|
3
|
+
declare type ShareConfig = Record<string, any>;
|
|
4
|
+
export interface ConfigOptions {
|
|
5
|
+
name: string;
|
|
6
|
+
entry: string;
|
|
7
|
+
filename: string;
|
|
8
|
+
outputDir: string;
|
|
9
|
+
publicPath: string;
|
|
10
|
+
shared?: ShareConfig;
|
|
11
|
+
externals: Configuration['externals'];
|
|
12
|
+
esmFullSpecific: Boolean;
|
|
13
|
+
exposes: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export declare function getConfig({ name, entry, filename, outputDir, publicPath, shared, externals, esmFullSpecific, exposes }: ConfigOptions): WebpackChain;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getConfig = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
9
|
+
const webpack_chain_1 = __importDefault(require("webpack-chain"));
|
|
10
|
+
const moduleFileExtensions = [
|
|
11
|
+
'.web.mjs',
|
|
12
|
+
'.mjs',
|
|
13
|
+
'.web.js',
|
|
14
|
+
'.js',
|
|
15
|
+
'.json',
|
|
16
|
+
'.web.jsx',
|
|
17
|
+
'.jsx'
|
|
18
|
+
];
|
|
19
|
+
function getConfig({ name, entry, filename, outputDir, publicPath, shared, externals, esmFullSpecific, exposes }) {
|
|
20
|
+
const config = new webpack_chain_1.default();
|
|
21
|
+
config.mode('development');
|
|
22
|
+
config.entry('main').add(entry);
|
|
23
|
+
config.devtool('cheap-module-source-map');
|
|
24
|
+
config.bail(true);
|
|
25
|
+
config.watch(false);
|
|
26
|
+
config.set('infrastructureLogging', {
|
|
27
|
+
level: 'none'
|
|
28
|
+
});
|
|
29
|
+
config.output.merge({
|
|
30
|
+
pathinfo: false,
|
|
31
|
+
path: outputDir,
|
|
32
|
+
chunkFilename: '[name].js',
|
|
33
|
+
publicPath,
|
|
34
|
+
uniqueName: name
|
|
35
|
+
});
|
|
36
|
+
config.performance.hints(false);
|
|
37
|
+
config.optimization.merge({
|
|
38
|
+
emitOnErrors: true,
|
|
39
|
+
checkWasmTypes: false,
|
|
40
|
+
// need to use DefinePlugin to set process.env.NODE_ENV
|
|
41
|
+
nodeEnv: false,
|
|
42
|
+
runtimeChunk: false,
|
|
43
|
+
minimize: false,
|
|
44
|
+
realContentHash: false
|
|
45
|
+
});
|
|
46
|
+
config.optimization.splitChunks({
|
|
47
|
+
chunks: 'all',
|
|
48
|
+
maxInitialRequests: Infinity,
|
|
49
|
+
minSize: 0,
|
|
50
|
+
cacheGroups: {
|
|
51
|
+
vendor: {
|
|
52
|
+
test: /.+/,
|
|
53
|
+
name(_module, _chunks, cacheGroupKey) {
|
|
54
|
+
return `_${cacheGroupKey}`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
config.resolve.extensions.merge(moduleFileExtensions);
|
|
60
|
+
config.module.set('strictExportPresence', true);
|
|
61
|
+
// x-ref: https://github.com/webpack/webpack/issues/11467
|
|
62
|
+
if (!esmFullSpecific) {
|
|
63
|
+
config.module
|
|
64
|
+
.rule('webpackPatch')
|
|
65
|
+
.test(/\.m?js/)
|
|
66
|
+
.resolve.set('fullySpecified', false);
|
|
67
|
+
}
|
|
68
|
+
config.module
|
|
69
|
+
.rule('js')
|
|
70
|
+
.test(/\.(js|mjs|cjs|jsx)$/)
|
|
71
|
+
.use('esbuild-loader')
|
|
72
|
+
.loader(require.resolve('esbuild-loader'))
|
|
73
|
+
.options({
|
|
74
|
+
loader: 'jsx',
|
|
75
|
+
target: 'es2015' // Syntax to compile to (see options below for possible values)
|
|
76
|
+
});
|
|
77
|
+
const DLL_VERSION = require('../../../../package.json').version;
|
|
78
|
+
const stringifiedConfig = Object.entries({
|
|
79
|
+
esmFullSpecific,
|
|
80
|
+
shared
|
|
81
|
+
}).reduce((prev, [key, value]) => {
|
|
82
|
+
return `${prev}|${key}=${JSON.stringify(value)}`;
|
|
83
|
+
}, '');
|
|
84
|
+
config.cache({
|
|
85
|
+
cacheDirectory: path_1.default.join(outputDir, '../cache'),
|
|
86
|
+
type: 'filesystem',
|
|
87
|
+
name: `dll-cache}-${config.get('mode')}`,
|
|
88
|
+
version: `${DLL_VERSION}|${stringifiedConfig}`
|
|
89
|
+
});
|
|
90
|
+
config.plugin('private/ignore-plugin').use(webpack_1.default.IgnorePlugin, [
|
|
91
|
+
{
|
|
92
|
+
resourceRegExp: /^\.\/locale$/,
|
|
93
|
+
contextRegExp: /moment$/
|
|
94
|
+
}
|
|
95
|
+
]);
|
|
96
|
+
config.plugin('define').use(webpack_1.default.DefinePlugin, [
|
|
97
|
+
{
|
|
98
|
+
'process.env.NODE_ENV': JSON.stringify('development')
|
|
99
|
+
}
|
|
100
|
+
]);
|
|
101
|
+
config.plugin('private/mf').use(webpack_1.default.container.ModuleFederationPlugin, [
|
|
102
|
+
{
|
|
103
|
+
library: {
|
|
104
|
+
type: 'global',
|
|
105
|
+
name
|
|
106
|
+
},
|
|
107
|
+
name,
|
|
108
|
+
filename,
|
|
109
|
+
exposes,
|
|
110
|
+
shared
|
|
111
|
+
}
|
|
112
|
+
]);
|
|
113
|
+
config.externals(externals);
|
|
114
|
+
return config;
|
|
115
|
+
}
|
|
116
|
+
exports.getConfig = getConfig;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const NAME = "dll";
|
|
2
|
+
export declare const MF_VA_PREFIX = "vf_";
|
|
3
|
+
export declare const DEFAULT_PUBLIC_PATH: string;
|
|
4
|
+
export declare const DLL_FILENAME = "dll.js";
|
|
5
|
+
export declare const METADATA_FILENAME = "_metadata.json";
|
|
6
|
+
export declare const UPDATE_FILENAME = "_update.json";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UPDATE_FILENAME = exports.METADATA_FILENAME = exports.DLL_FILENAME = exports.DEFAULT_PUBLIC_PATH = exports.MF_VA_PREFIX = exports.NAME = void 0;
|
|
4
|
+
exports.NAME = 'dll';
|
|
5
|
+
exports.MF_VA_PREFIX = 'vf_';
|
|
6
|
+
exports.DEFAULT_PUBLIC_PATH = `/__${exports.NAME}/`;
|
|
7
|
+
exports.DLL_FILENAME = 'dll.js';
|
|
8
|
+
exports.METADATA_FILENAME = '_metadata.json';
|
|
9
|
+
exports.UPDATE_FILENAME = '_update.json';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCJSExports = void 0;
|
|
4
|
+
function getCJSExports({ content }) {
|
|
5
|
+
return matchAll(/Object\.defineProperty\(\s*exports\s*\,\s*[\"|\'](\w+)[\"|\']/g, content)
|
|
6
|
+
.concat(
|
|
7
|
+
// Support export['default']
|
|
8
|
+
// ref: https://unpkg.alibaba-inc.com/browse/echarts-for-react@2.0.16/lib/core.js
|
|
9
|
+
matchAll(/exports(?:\.|\[(?:\'|\"))(\w+)(?:\s*|(?:\'|\")\])\s*\=/g, content))
|
|
10
|
+
.concat(
|
|
11
|
+
// Support __webpack_exports__["default"]
|
|
12
|
+
// ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8429
|
|
13
|
+
matchAll(/__webpack_exports__\[(?:\"|\')(\w+)(?:\"|\')\]\s*\=/g, content))
|
|
14
|
+
.concat(
|
|
15
|
+
// Support __webpack_require__.d(__webpack_exports, "EditorState")
|
|
16
|
+
// ref: https://github.com/margox/braft-editor/blob/master/dist/index.js#L8347
|
|
17
|
+
matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(?:\"|\')(\w+)(?:\"|\')\s*,/g, content))
|
|
18
|
+
.concat(
|
|
19
|
+
// Support __webpack_require__.d(__webpack_exports__, {"default": function() { return /* binding */ clipboard; }});
|
|
20
|
+
// ref: https://unpkg.alibaba-inc.com/browse/clipboard@2.0.8/dist/clipboard.js L26
|
|
21
|
+
...matchAll(/__webpack_require__\.d\(\s*__webpack_exports__\s*,\s*(\{)/g, content).map(matchResult => {
|
|
22
|
+
const { index } = matchResult;
|
|
23
|
+
let idx = index;
|
|
24
|
+
let deep = 0;
|
|
25
|
+
let isMeetSymbol = false;
|
|
26
|
+
let symbolBeginIndex = index;
|
|
27
|
+
while (idx < content.length) {
|
|
28
|
+
if (!deep && isMeetSymbol) {
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
if (content[idx] === '{') {
|
|
32
|
+
if (!isMeetSymbol) {
|
|
33
|
+
isMeetSymbol = true;
|
|
34
|
+
symbolBeginIndex = idx;
|
|
35
|
+
}
|
|
36
|
+
deep++;
|
|
37
|
+
}
|
|
38
|
+
if (content[idx] === '}') {
|
|
39
|
+
deep--;
|
|
40
|
+
}
|
|
41
|
+
idx++;
|
|
42
|
+
}
|
|
43
|
+
let result = content.slice(symbolBeginIndex, idx);
|
|
44
|
+
return [
|
|
45
|
+
...matchAll(/(?:\"|\')(\w+)(?:\"|\')\s*\:\s*(?:function|\()/g, result)
|
|
46
|
+
];
|
|
47
|
+
}))
|
|
48
|
+
.map(result => result[1]);
|
|
49
|
+
}
|
|
50
|
+
exports.getCJSExports = getCJSExports;
|
|
51
|
+
function matchAll(regexp, str) {
|
|
52
|
+
const result = [];
|
|
53
|
+
let match;
|
|
54
|
+
while ((match = regexp.exec(str)) !== null) {
|
|
55
|
+
result.push(match);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getExposeFromContent(libraryPath: string): Promise<string>;
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getExposeFromContent = void 0;
|
|
16
|
+
const assert_1 = __importDefault(require("assert"));
|
|
17
|
+
const fs_extra_1 = require("fs-extra");
|
|
18
|
+
const path_1 = require("path");
|
|
19
|
+
const getModuleExports_1 = require("./getModuleExports");
|
|
20
|
+
function getExposeFromContent(libraryPath) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
// Support CSS
|
|
23
|
+
if (/\.(css|less|scss|sass|stylus|styl)$/.test(libraryPath)) {
|
|
24
|
+
return `import '${libraryPath}';`;
|
|
25
|
+
}
|
|
26
|
+
// Support Assets Files
|
|
27
|
+
if (/\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(libraryPath)) {
|
|
28
|
+
return `
|
|
29
|
+
import _ from '${libraryPath}';
|
|
30
|
+
export default _;`.trim();
|
|
31
|
+
}
|
|
32
|
+
(0, assert_1.default)(/(js|jsx|mjs|ts|tsx)$/.test(libraryPath), `file type not supported for ${(0, path_1.basename)(libraryPath)}.`);
|
|
33
|
+
const content = (0, fs_extra_1.readFileSync)(libraryPath, 'utf-8');
|
|
34
|
+
const { exports, isCJS } = yield (0, getModuleExports_1.getModuleExports)({
|
|
35
|
+
content,
|
|
36
|
+
libraryPath
|
|
37
|
+
});
|
|
38
|
+
// cjs
|
|
39
|
+
if (isCJS) {
|
|
40
|
+
return [
|
|
41
|
+
`import _ from '${libraryPath}';`,
|
|
42
|
+
`export default _;`,
|
|
43
|
+
`export * from '${libraryPath}';`
|
|
44
|
+
].join('\n');
|
|
45
|
+
}
|
|
46
|
+
// esm
|
|
47
|
+
else {
|
|
48
|
+
const ret = [];
|
|
49
|
+
let hasExports = false;
|
|
50
|
+
if (exports.includes('default')) {
|
|
51
|
+
ret.push(`import _ from '${libraryPath}';`);
|
|
52
|
+
ret.push(`export default _;`);
|
|
53
|
+
hasExports = true;
|
|
54
|
+
}
|
|
55
|
+
if (hasNonDefaultExports(exports) ||
|
|
56
|
+
// export * from 不会有 exports,只会有 imports
|
|
57
|
+
/export\s+\*\s+from/.test(content)) {
|
|
58
|
+
ret.push(`export * from '${libraryPath}';`);
|
|
59
|
+
hasExports = true;
|
|
60
|
+
}
|
|
61
|
+
if (!hasExports) {
|
|
62
|
+
// 只有 __esModule 的全量导出
|
|
63
|
+
if (exports.includes('__esModule') && exports.length > 1) {
|
|
64
|
+
ret.push(`import _ from '${libraryPath}';`);
|
|
65
|
+
ret.push(`export default _;`);
|
|
66
|
+
ret.push(`export * from '${libraryPath}';`);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
ret.push(`import '${libraryPath}';`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return ret.join('\n');
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
exports.getExposeFromContent = getExposeFromContent;
|
|
77
|
+
function hasNonDefaultExports(exports) {
|
|
78
|
+
return (exports.filter((exp) => !['__esModule', 'default'].includes(exp))
|
|
79
|
+
.length > 0);
|
|
80
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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.getModuleExports = void 0;
|
|
13
|
+
// @ts-ignore: es-module-lexer misconfigure its package.exports
|
|
14
|
+
const es_module_lexer_1 = require("es-module-lexer");
|
|
15
|
+
const esbuild_1 = require("esbuild");
|
|
16
|
+
const path_1 = require("path");
|
|
17
|
+
const getCJSExports_1 = require("./getCJSExports");
|
|
18
|
+
function getModuleExports({ content, libraryPath }) {
|
|
19
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
// Support tsx and jsx
|
|
21
|
+
if (/\.(tsx|jsx)$/.test(libraryPath)) {
|
|
22
|
+
content = (yield (0, esbuild_1.transform)(content, {
|
|
23
|
+
sourcemap: false,
|
|
24
|
+
sourcefile: libraryPath,
|
|
25
|
+
format: 'esm',
|
|
26
|
+
target: 'es6',
|
|
27
|
+
loader: (0, path_1.extname)(libraryPath).slice(1)
|
|
28
|
+
})).code;
|
|
29
|
+
}
|
|
30
|
+
yield es_module_lexer_1.init;
|
|
31
|
+
const [imports, exports] = (0, es_module_lexer_1.parse)(content);
|
|
32
|
+
let isCJS = !imports.length && !exports.length;
|
|
33
|
+
let cjsEsmExports = null;
|
|
34
|
+
if (isCJS) {
|
|
35
|
+
cjsEsmExports = (0, getCJSExports_1.getCJSExports)({ content });
|
|
36
|
+
if (cjsEsmExports.includes('__esModule')) {
|
|
37
|
+
isCJS = false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
exports: cjsEsmExports || exports,
|
|
42
|
+
isCJS
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
exports.getModuleExports = getModuleExports;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare class Dep {
|
|
2
|
+
request: string;
|
|
3
|
+
version: string | null;
|
|
4
|
+
libraryPath: string;
|
|
5
|
+
filename: string;
|
|
6
|
+
constructor(opts: {
|
|
7
|
+
outputPath: string;
|
|
8
|
+
request: string;
|
|
9
|
+
libraryPath: string;
|
|
10
|
+
version: string | null;
|
|
11
|
+
});
|
|
12
|
+
buildExposeContent(): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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.Dep = void 0;
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
const getExposeFromContent_1 = require("./getExposeFromContent");
|
|
16
|
+
function trimFileContent(content) {
|
|
17
|
+
return content.trim() + '\n';
|
|
18
|
+
}
|
|
19
|
+
class Dep {
|
|
20
|
+
constructor(opts) {
|
|
21
|
+
this.request = opts.request;
|
|
22
|
+
this.libraryPath = opts.libraryPath;
|
|
23
|
+
this.version = opts.version;
|
|
24
|
+
const name = this.request.replace(/\//g, '_').replace(/:/g, '_');
|
|
25
|
+
this.filename = (0, path_1.join)(opts.outputPath, `${constants_1.MF_VA_PREFIX}${name}.js`);
|
|
26
|
+
}
|
|
27
|
+
buildExposeContent() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
// node natives
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const isNodeNatives = !!process.binding('natives')[this.request];
|
|
32
|
+
if (isNodeNatives) {
|
|
33
|
+
return trimFileContent(`
|
|
34
|
+
import _ from '${this.request}';
|
|
35
|
+
export default _;
|
|
36
|
+
export * from '${this.request}';
|
|
37
|
+
`);
|
|
38
|
+
}
|
|
39
|
+
return yield (0, getExposeFromContent_1.getExposeFromContent)(this.libraryPath);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.Dep = Dep;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const checkNotInNodeModules: (libraryName: string, rootDir: string) => boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkNotInNodeModules = void 0;
|
|
4
|
+
const checkNotInNodeModules = (libraryName, rootDir) => {
|
|
5
|
+
try {
|
|
6
|
+
require.resolve(libraryName, {
|
|
7
|
+
paths: [rootDir]
|
|
8
|
+
});
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
catch (e) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.checkNotInNodeModules = checkNotInNodeModules;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from 'http';
|
|
2
|
+
import type * as webpackType from 'webpack';
|
|
3
|
+
import type { Configuration } from 'webpack';
|
|
4
|
+
import type WebpackChain from 'webpack-chain';
|
|
5
|
+
import { ShareConfig } from './bundler';
|
|
6
|
+
declare type IResolveWebpackModule = <T extends string>(path: T) => T extends `webpack` ? typeof webpackType : T extends `webpack/${infer R}` ? any : never;
|
|
7
|
+
interface IOpts {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
rootDir: string;
|
|
10
|
+
cacheDir: string;
|
|
11
|
+
resolveWebpackModule?: IResolveWebpackModule;
|
|
12
|
+
include?: RegExp[];
|
|
13
|
+
exclude?: RegExp[];
|
|
14
|
+
shared?: ShareConfig;
|
|
15
|
+
externals?: Configuration['externals'];
|
|
16
|
+
esmFullSpecific?: Boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare class DynamicDll {
|
|
19
|
+
private _opts;
|
|
20
|
+
private _bundler;
|
|
21
|
+
private _rootDir;
|
|
22
|
+
private _cacheDir;
|
|
23
|
+
private _resolveWebpackModule;
|
|
24
|
+
private _dllPlugin;
|
|
25
|
+
private _hasBuilt;
|
|
26
|
+
constructor(opts: IOpts);
|
|
27
|
+
private getRemovedModules;
|
|
28
|
+
private handleSnapshot;
|
|
29
|
+
middleware: (req: IncomingMessage, res: ServerResponse, next: (...args: any[]) => any) => Promise<any>;
|
|
30
|
+
modifyWebpackChain: (chain: WebpackChain) => WebpackChain;
|
|
31
|
+
modifyWebpack: (config: Configuration) => Configuration;
|
|
32
|
+
private _buildDLL;
|
|
33
|
+
private _getMFconfig;
|
|
34
|
+
}
|
|
35
|
+
export {};
|