@dtwo/webpack-builder 3.1.1 → 3.1.2
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/dist/index.mjs +27 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,7 @@ import { isAbsolute, relative, join, resolve, normalize, dirname } from 'pathe';
|
|
|
11
11
|
import { walk } from 'estree-walker';
|
|
12
12
|
import MagicString from 'magic-string';
|
|
13
13
|
import { hash } from 'ohash';
|
|
14
|
+
import { findStaticImports, parseStaticImport, createCommonJS } from 'mlly';
|
|
14
15
|
import { createFsFromVolume, Volume } from 'memfs';
|
|
15
16
|
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
|
16
17
|
import querystring from 'node:querystring';
|
|
@@ -27,7 +28,6 @@ import hash$1 from 'hash-sum';
|
|
|
27
28
|
import fse from 'fs-extra';
|
|
28
29
|
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
29
30
|
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
|
|
30
|
-
import { createCommonJS } from 'mlly';
|
|
31
31
|
import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
|
32
32
|
|
|
33
33
|
const keyedFunctions = [
|
|
@@ -53,6 +53,7 @@ const composableKeysPlugin = createUnplugin((options) => {
|
|
|
53
53
|
}
|
|
54
54
|
const { 0: script = code, index: codeIndex = 0 } = code.match(/(?<=<script[^>]*>)[\S\s.]*?(?=<\/script>)/) || { index: 0, 0: code };
|
|
55
55
|
const s = new MagicString(code);
|
|
56
|
+
let imports;
|
|
56
57
|
let count = 0;
|
|
57
58
|
const relativeID = isAbsolute(id) ? relative(options.rootDir, id) : id;
|
|
58
59
|
walk(this.parse(script, {
|
|
@@ -68,6 +69,10 @@ const composableKeysPlugin = createUnplugin((options) => {
|
|
|
68
69
|
if (!name || !keyedFunctions.includes(name) || node.arguments.length >= 4) {
|
|
69
70
|
return;
|
|
70
71
|
}
|
|
72
|
+
imports = imports || detectImportNames(script);
|
|
73
|
+
if (imports.has(name)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
71
76
|
switch (name) {
|
|
72
77
|
case "useState":
|
|
73
78
|
if (node.arguments.length >= 2 || stringTypes.includes(node.arguments[0]?.type)) {
|
|
@@ -103,6 +108,27 @@ const composableKeysPlugin = createUnplugin((options) => {
|
|
|
103
108
|
}
|
|
104
109
|
};
|
|
105
110
|
});
|
|
111
|
+
const DTWO_IMPORT_RE = /dtwo|#app|#imports/;
|
|
112
|
+
function detectImportNames(code) {
|
|
113
|
+
const imports = findStaticImports(code);
|
|
114
|
+
const names = /* @__PURE__ */ new Set();
|
|
115
|
+
for (const i of imports) {
|
|
116
|
+
if (DTWO_IMPORT_RE.test(i.specifier)) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const { namedImports, defaultImport, namespacedImport } = parseStaticImport(i);
|
|
120
|
+
for (const name in namedImports || {}) {
|
|
121
|
+
names.add(namedImports[name]);
|
|
122
|
+
}
|
|
123
|
+
if (defaultImport) {
|
|
124
|
+
names.add(defaultImport);
|
|
125
|
+
}
|
|
126
|
+
if (namespacedImport) {
|
|
127
|
+
names.add(namespacedImport);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return names;
|
|
131
|
+
}
|
|
106
132
|
|
|
107
133
|
const defaults = {
|
|
108
134
|
globalPublicPath: "__webpack_public_path__",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dtwo/webpack-builder",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"repository": "d2js/dtwo",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@babel/core": "7.20.12",
|
|
17
17
|
"@d2js/friendly-errors-webpack-plugin": "2.5.2",
|
|
18
|
-
"@dtwo/kit": "3.1.
|
|
18
|
+
"@dtwo/kit": "3.1.2",
|
|
19
19
|
"@dtwo/unplugin": "1.0.0",
|
|
20
20
|
"autoprefixer": "10.4.13",
|
|
21
21
|
"css-loader": "6.7.3",
|
|
@@ -54,18 +54,18 @@
|
|
|
54
54
|
"webpackbar": "5.0.2"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@dtwo/schema": "3.1.
|
|
57
|
+
"@dtwo/schema": "3.1.2",
|
|
58
58
|
"@types/lodash-es": "4.17.6",
|
|
59
59
|
"@types/pify": "5.0.1",
|
|
60
60
|
"@types/webpack-bundle-analyzer": "4.6.0",
|
|
61
61
|
"@types/webpack-dev-middleware": "5.3.0",
|
|
62
62
|
"@types/webpack-hot-middleware": "2.25.6",
|
|
63
63
|
"@types/webpack-virtual-modules": "0.1.1",
|
|
64
|
-
"kdu": "3.2.
|
|
64
|
+
"kdu": "3.2.48",
|
|
65
65
|
"unbuild": "1.1.1"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"kdu": "^3.2.
|
|
68
|
+
"kdu": "^3.2.47"
|
|
69
69
|
},
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|