@dtwo/webpack-builder 3.1.1 → 3.2.0

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 (2) hide show
  1. package/dist/index.mjs +50 -5
  2. package/package.json +8 -8
package/dist/index.mjs CHANGED
@@ -11,24 +11,24 @@ 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';
17
18
  import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
19
+ import ForkTSCheckerWebpackPlugin from '@dtwojs/fork-ts-checker-webpack-plugin';
18
20
  import { cloneDeep, uniq, defaults as defaults$1, merge } from 'lodash-es';
19
21
  import TimeFixPlugin from 'time-fix-plugin';
20
22
  import WebpackBar from 'webpackbar';
21
23
  import FriendlyErrorsWebpackPlugin from '@d2js/friendly-errors-webpack-plugin';
22
24
  import escapeRegExp from 'escape-string-regexp';
23
- import esbuildLoader from 'esbuild-loader';
25
+ import { EsbuildPlugin } from 'esbuild-loader';
24
26
  import KduLoaderPlugin from 'kdu-loader/dist/pluginWebpack5.js';
25
27
  import { normalizeWebpackManifest } from 'kdu-bundle-renderer';
26
28
  import hash$1 from 'hash-sum';
27
29
  import fse from 'fs-extra';
28
30
  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
29
31
  import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
30
- import { createCommonJS } from 'mlly';
31
- import ForkTSCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
32
32
 
33
33
  const keyedFunctions = [
34
34
  "useState",
@@ -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__",
@@ -445,7 +471,7 @@ function getEnv(ctx) {
445
471
  function esbuild(ctx) {
446
472
  const { config } = ctx;
447
473
  const target = ctx.isServer ? "es2019" : "chrome85";
448
- config.optimization.minimizer.push(new esbuildLoader.ESBuildMinifyPlugin());
474
+ config.optimization.minimizer.push(new EsbuildPlugin());
449
475
  config.module.rules.push(
450
476
  {
451
477
  test: /\.m?[jt]s$/i,
@@ -944,6 +970,18 @@ function clientPlugins(ctx) {
944
970
  ...options.webpack.analyze === true ? {} : options.webpack.analyze
945
971
  }));
946
972
  }
973
+ if (!ctx.dtwo.options.ssr) {
974
+ if (ctx.dtwo.options.typescript.typeCheck === true || ctx.dtwo.options.typescript.typeCheck === "build" && !ctx.dtwo.options.dev) {
975
+ config.plugins.push(new ForkTSCheckerWebpackPlugin({
976
+ logger,
977
+ typescript: {
978
+ extensions: {
979
+ kdu: { compiler: "@kdujs/compiler-sfc" }
980
+ }
981
+ }
982
+ }));
983
+ }
984
+ }
947
985
  }
948
986
 
949
987
  function node(ctx) {
@@ -1040,7 +1078,14 @@ function serverPlugins(ctx) {
1040
1078
  }));
1041
1079
  }
1042
1080
  if (ctx.dtwo.options.typescript.typeCheck === true || ctx.dtwo.options.typescript.typeCheck === "build" && !ctx.dtwo.options.dev) {
1043
- config.plugins.push(new ForkTSCheckerWebpackPlugin({ logger }));
1081
+ config.plugins.push(new ForkTSCheckerWebpackPlugin({
1082
+ logger,
1083
+ typescript: {
1084
+ extensions: {
1085
+ kdu: { compiler: "@kdujs/compiler-sfc" }
1086
+ }
1087
+ }
1088
+ }));
1044
1089
  }
1045
1090
  }
1046
1091
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtwo/webpack-builder",
3
- "version": "3.1.1",
3
+ "version": "3.2.0",
4
4
  "repository": "d2js/dtwo",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -15,20 +15,20 @@
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.1",
18
+ "@dtwo/kit": "3.2.0",
19
19
  "@dtwo/unplugin": "1.0.0",
20
+ "@dtwojs/fork-ts-checker-webpack-plugin": "7.3.0",
20
21
  "autoprefixer": "10.4.13",
21
22
  "css-loader": "6.7.3",
22
23
  "css-minimizer-webpack-plugin": "4.2.2",
23
24
  "cssnano": "5.1.14",
24
- "esbuild-loader": "2.21.0",
25
+ "esbuild-loader": "3.0.0",
25
26
  "escape-string-regexp": "5.0.0",
26
27
  "estree-walker": "3.0.3",
27
28
  "file-loader": "6.2.0",
28
- "fork-ts-checker-webpack-plugin": "7.3.0",
29
29
  "fs-extra": "11.1.0",
30
30
  "hash-sum": "2.0.0",
31
- "kdu-bundle-renderer": "1.0.0",
31
+ "kdu-bundle-renderer": "1.0.1",
32
32
  "kdu-loader": "17.0.0",
33
33
  "lodash-es": "4.17.21",
34
34
  "magic-string": "0.27.0",
@@ -54,18 +54,18 @@
54
54
  "webpackbar": "5.0.2"
55
55
  },
56
56
  "devDependencies": {
57
- "@dtwo/schema": "3.1.1",
57
+ "@dtwo/schema": "3.2.0",
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.45",
64
+ "kdu": "3.2.48",
65
65
  "unbuild": "1.1.1"
66
66
  },
67
67
  "peerDependencies": {
68
- "kdu": "^3.2.45"
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"