@nimbus-ds/webpack 1.5.0-rc.2 → 1.5.0-rc.4

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.
@@ -1,10 +1,5 @@
1
1
  import { Configuration } from "webpack";
2
- import { MoveFilesIntoDistFolderPluginOptions } from "../plugins/MoveFilesIntoDistFolderPlugin";
3
- export declare const getConfiguration: (config?: Configuration, extraParams?: {
4
- dtsBundleConfig?: {
5
- entries: string[];
6
- };
7
- packageJsonConfig?: MoveFilesIntoDistFolderPluginOptions;
8
- }) => Configuration;
2
+ import { WebpackBaseConfig } from "../utils";
3
+ export declare const getConfiguration: (config?: Configuration, extraParams?: WebpackBaseConfig) => Configuration;
9
4
  declare const _default: Configuration;
10
5
  export default _default;
@@ -13,19 +13,14 @@ const alias_1 = require("./alias");
13
13
  const external_1 = require("./external");
14
14
  const production_1 = tslib_1.__importDefault(require("./production"));
15
15
  const development_1 = tslib_1.__importDefault(require("./development"));
16
- const MoveFilesIntoDistFolderPlugin_1 = tslib_1.__importDefault(require("../plugins/MoveFilesIntoDistFolderPlugin"));
17
- const webpack = (dtsBundleConfig, packageJsonConfig) => ({
16
+ const webpack = ({ dtsBundleConfig, packageJsonConfig, useClientInjectionOptions, } = {}) => ({
18
17
  target: "node",
19
18
  mode: utils_1.isProduction ? "production" : "development",
20
19
  entry: {
21
20
  "./index": "./src/index.ts",
22
21
  },
23
22
  output: {
24
- filename: (pathData) => {
25
- return pathData.chunk?.name === "./index"
26
- ? "[name].js"
27
- : "[name]/index.js";
28
- },
23
+ filename: (pathData) => pathData.chunk?.name === "./index" ? "[name].js" : "[name]/index.js",
29
24
  library: {
30
25
  name: ["@nimbus-ds", "[name]"],
31
26
  type: "umd",
@@ -37,8 +32,8 @@ const webpack = (dtsBundleConfig, packageJsonConfig) => ({
37
32
  },
38
33
  plugins: [
39
34
  (0, plugins_1.dtsBundleGeneratorPlugin)(dtsBundleConfig),
40
- new MoveFilesIntoDistFolderPlugin_1.default(packageJsonConfig),
41
- new plugins_1.UseClientInjectionPlugin(),
35
+ new plugins_1.MoveFilesIntoDistFolderPlugin(packageJsonConfig),
36
+ new plugins_1.UseClientInjectionPlugin(useClientInjectionOptions),
42
37
  ],
43
38
  resolve: {
44
39
  alias: alias_1.aliasItems,
@@ -47,7 +42,7 @@ const webpack = (dtsBundleConfig, packageJsonConfig) => ({
47
42
  externals: external_1.externalItems,
48
43
  });
49
44
  const getConfiguration = (config, extraParams) => utils_1.isProduction
50
- ? (0, webpack_merge_1.default)(webpack(extraParams?.dtsBundleConfig, extraParams?.packageJsonConfig), production_1.default, config || {})
45
+ ? (0, webpack_merge_1.default)(webpack(extraParams), production_1.default, config || {})
51
46
  : (0, webpack_merge_1.default)(webpack(), development_1.default, config || {});
52
47
  exports.getConfiguration = getConfiguration;
53
48
  exports.default = (0, exports.getConfiguration)();
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/config/base.ts"],"names":[],"mappings":";;;;AAAA;;GAEG;AACH,0EAAkC;AAGlC,oCAA0D;AAC1D,oCAAmD;AACnD,wCAAgF;AAChF,mCAAqC;AACrC,yCAA2C;AAE3C,sEAAsC;AACtC,wEAAwC;AACxC,qHAEkD;AAElD,MAAM,OAAO,GAAG,CACd,eAAuC,EACvC,iBAAwD,EACzC,EAAE,CAAC,CAAC;IACnB,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,oBAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa;IACjD,KAAK,EAAE;QACL,SAAS,EAAE,gBAAgB;KAC5B;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE;YACrB,OAAO,QAAQ,CAAC,KAAK,EAAE,IAAI,KAAK,SAAS;gBACvC,CAAC,CAAC,WAAW;gBACb,CAAC,CAAC,iBAAiB,CAAC;QACxB,CAAC;QACD,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,YAAY,EAAE,QA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;IACjD,KAAK,EAAE;QACL,SAAS,EAAE,gBAAgB;KAC5B;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,CAAC,QAAQ,EAAE,EAAE,CACrB,QAAQ,CAAC,KAAK,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,iBAAiB;QACtE,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,YAAY,EAAE,QAAQ,CAAC;YAC9B,IAAI,EAAE,KAAK;SACZ;QACD,aAAa,EAAE,KAAK;KACrB;IACD,MAAM,EAAE;QACN,KAAK,EAAE,IAAA,wBAAgB,EAAC,CAAC,sBAAc,EAAE,eAAO,CAAC,CAAC;KACnD;IACD,OAAO,EAAE;QACP,IAAA,kCAAwB,EAAC,eAAe,CAAC;QACzC,IAAI,uCAA6B,CAAC,iBAAiB,CAAC;QACpD,IAAI,kCAAwB,CAAC,yBAAyB,CAAC;KACxD;IACD,OAAO,EAAE;QACP,KAAK,EAAE,kBAAU;QACjB,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;KACnC;IACD,SAAS,EAAE,wBAAa;CACzB,CAAC,CAAC;AAEI,MAAM,gBAAgB,GAAG,CAC9B,MAAsB,EACtB,WAA+B,EAC/B,EAAE,CACF,oBAAY;IACV,CAAC,CAAC,IAAA,uBAAK,EAAC,OAAO,CAAC,WAAW,CAAC,EAAE,oBAAU,EAAE,MAAM,IAAI,EAAE,CAAC;IACvD,CAAC,CAAC,IAAA,uBAAK,EAAC,OAAO,EAAE,EAAE,qBAAW,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;AANrC,QAAA,gBAAgB,oBAMqB;AAElD,kBAAe,IAAA,wBAAgB,GAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { UseClientInjectionPlugin } from "./plugins";
2
- import MoveFilesIntoDistFolderPlugin from "./plugins/MoveFilesIntoDistFolderPlugin";
1
+ import { UseClientInjectionPlugin, MoveFilesIntoDistFolderPlugin } from "./plugins";
3
2
  export declare const rules: {
4
3
  cssLoaderExtractRule: {
5
4
  test: RegExp;
@@ -57,12 +56,7 @@ export declare const configuration: {
57
56
  development: import("webpack").Configuration;
58
57
  production: import("webpack").Configuration;
59
58
  base: import("webpack").Configuration;
60
- getConfiguration: (config?: import("webpack").Configuration | undefined, extraParams?: {
61
- dtsBundleConfig?: {
62
- entries: string[];
63
- } | undefined;
64
- packageJsonConfig?: import("./plugins/MoveFilesIntoDistFolderPlugin").MoveFilesIntoDistFolderPluginOptions | undefined;
65
- } | undefined) => import("webpack").Configuration;
59
+ getConfiguration: (config?: import("webpack").Configuration | undefined, extraParams?: import("./utils").WebpackBaseConfig | undefined) => import("webpack").Configuration;
66
60
  };
67
61
  export declare const utils: {
68
62
  rootDir: string;
@@ -79,6 +73,14 @@ export declare const utils: {
79
73
  }[];
80
74
  isProduction: boolean;
81
75
  isDevelopment: boolean;
76
+ getComponentsPackageExports: (baseDir: string, folders: string[]) => {
77
+ packageExports: Record<string, {
78
+ import: string;
79
+ require: string;
80
+ }>;
81
+ dtsCommands: string[];
82
+ webpackEntries: Record<string, string>;
83
+ };
82
84
  };
83
85
  declare const webpack: {
84
86
  rules: {
@@ -138,12 +140,7 @@ declare const webpack: {
138
140
  development: import("webpack").Configuration;
139
141
  production: import("webpack").Configuration;
140
142
  base: import("webpack").Configuration;
141
- getConfiguration: (config?: import("webpack").Configuration | undefined, extraParams?: {
142
- dtsBundleConfig?: {
143
- entries: string[];
144
- } | undefined;
145
- packageJsonConfig?: import("./plugins/MoveFilesIntoDistFolderPlugin").MoveFilesIntoDistFolderPluginOptions | undefined;
146
- } | undefined) => import("webpack").Configuration;
143
+ getConfiguration: (config?: import("webpack").Configuration | undefined, extraParams?: import("./utils").WebpackBaseConfig | undefined) => import("webpack").Configuration;
147
144
  };
148
145
  utils: {
149
146
  rootDir: string;
@@ -160,6 +157,14 @@ declare const webpack: {
160
157
  }[];
161
158
  isProduction: boolean;
162
159
  isDevelopment: boolean;
160
+ getComponentsPackageExports: (baseDir: string, folders: string[]) => {
161
+ packageExports: Record<string, {
162
+ import: string;
163
+ require: string;
164
+ }>;
165
+ dtsCommands: string[];
166
+ webpackEntries: Record<string, string>;
167
+ };
163
168
  };
164
169
  };
165
170
  export default webpack;
package/dist/index.js CHANGED
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.utils = exports.configuration = exports.plugins = exports.rules = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const config_1 = require("./config");
6
5
  const plugins_1 = require("./plugins");
7
- const MoveFilesIntoDistFolderPlugin_1 = tslib_1.__importDefault(require("./plugins/MoveFilesIntoDistFolderPlugin"));
8
6
  const rules_1 = require("./rules");
9
7
  const utils_1 = require("./utils");
10
8
  exports.rules = {
@@ -21,7 +19,7 @@ exports.plugins = {
21
19
  cssMinimizerPlugin: plugins_1.cssMinimizerPlugin,
22
20
  dtsBundleGeneratorPlugin: plugins_1.dtsBundleGeneratorPlugin,
23
21
  UseClientInjectionPlugin: plugins_1.UseClientInjectionPlugin,
24
- MoveFilesIntoDistFolderPlugin: MoveFilesIntoDistFolderPlugin_1.default
22
+ MoveFilesIntoDistFolderPlugin: plugins_1.MoveFilesIntoDistFolderPlugin,
25
23
  };
26
24
  exports.configuration = {
27
25
  aliasItems: config_1.aliasItems,
@@ -31,7 +29,13 @@ exports.configuration = {
31
29
  base: config_1.base,
32
30
  getConfiguration: config_1.getConfiguration,
33
31
  };
34
- exports.utils = { rootDir: utils_1.rootDir, arrayFilterEmpty: utils_1.arrayFilterEmpty, isProduction: utils_1.isProduction, isDevelopment: utils_1.isDevelopment };
32
+ exports.utils = {
33
+ rootDir: utils_1.rootDir,
34
+ arrayFilterEmpty: utils_1.arrayFilterEmpty,
35
+ isProduction: utils_1.isProduction,
36
+ isDevelopment: utils_1.isDevelopment,
37
+ getComponentsPackageExports: utils_1.getComponentsPackageExports,
38
+ };
35
39
  const webpack = {
36
40
  rules: exports.rules,
37
41
  plugins: exports.plugins,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,qCAOkB;AAClB,uCAOmB;AACnB,oHAAoF;AACpF,mCAMiB;AACjB,mCAKiB;AAEJ,QAAA,KAAK,GAAG;IACnB,oBAAoB,EAApB,4BAAoB;IACpB,kBAAkB,EAAlB,0BAAkB;IAClB,kBAAkB,EAAlB,0BAAkB;IAClB,cAAc,EAAd,sBAAc;IACd,OAAO,EAAP,eAAO;CACR,CAAC;AACW,QAAA,OAAO,GAAG;IACrB,oBAAoB,EAApB,8BAAoB;IACpB,oBAAoB,EAApB,8BAAoB;IACpB,oBAAoB,EAApB,8BAAoB;IACpB,kBAAkB,EAAlB,4BAAkB;IAClB,wBAAwB,EAAxB,kCAAwB;IACxB,wBAAwB,EAAxB,kCAAwB;IACxB,6BAA6B,EAA7B,uCAA6B;CAC9B,CAAC;AACW,QAAA,aAAa,GAAG;IAC3B,UAAU,EAAV,mBAAU;IACV,YAAY,EAAZ,qBAAY;IACZ,WAAW,EAAX,oBAAW;IACX,UAAU,EAAV,mBAAU;IACV,IAAI,EAAJ,aAAI;IACJ,gBAAgB,EAAhB,yBAAgB;CACjB,CAAC;AAEW,QAAA,KAAK,GAAG,EAAE,OAAO,EAAP,eAAO,EAAE,gBAAgB,EAAhB,wBAAgB,EAAE,YAAY,EAAZ,oBAAY,EAAE,aAAa,EAAb,qBAAa,EAAE,CAAC;AAEhF,MAAM,OAAO,GAAG;IACd,KAAK,EAAL,aAAK;IACL,OAAO,EAAP,eAAO;IACP,aAAa,EAAb,qBAAa;IACb,KAAK,EAAL,aAAK;CACN,CAAC;AAEF,kBAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAOkB;AAClB,uCAQmB;AACnB,mCAMiB;AACjB,mCAMiB;AAEJ,QAAA,KAAK,GAAG;IACnB,oBAAoB,EAApB,4BAAoB;IACpB,kBAAkB,EAAlB,0BAAkB;IAClB,kBAAkB,EAAlB,0BAAkB;IAClB,cAAc,EAAd,sBAAc;IACd,OAAO,EAAP,eAAO;CACR,CAAC;AACW,QAAA,OAAO,GAAG;IACrB,oBAAoB,EAApB,8BAAoB;IACpB,oBAAoB,EAApB,8BAAoB;IACpB,oBAAoB,EAApB,8BAAoB;IACpB,kBAAkB,EAAlB,4BAAkB;IAClB,wBAAwB,EAAxB,kCAAwB;IACxB,wBAAwB,EAAxB,kCAAwB;IACxB,6BAA6B,EAA7B,uCAA6B;CAC9B,CAAC;AACW,QAAA,aAAa,GAAG;IAC3B,UAAU,EAAV,mBAAU;IACV,YAAY,EAAZ,qBAAY;IACZ,WAAW,EAAX,oBAAW;IACX,UAAU,EAAV,mBAAU;IACV,IAAI,EAAJ,aAAI;IACJ,gBAAgB,EAAhB,yBAAgB;CACjB,CAAC;AAEW,QAAA,KAAK,GAAG;IACnB,OAAO,EAAP,eAAO;IACP,gBAAgB,EAAhB,wBAAgB;IAChB,YAAY,EAAZ,oBAAY;IACZ,aAAa,EAAb,qBAAa;IACb,2BAA2B,EAA3B,mCAA2B;CAC5B,CAAC;AAEF,MAAM,OAAO,GAAG;IACd,KAAK,EAAL,aAAK;IACL,OAAO,EAAP,eAAO;IACP,aAAa,EAAb,qBAAa;IACb,KAAK,EAAL,aAAK;CACN,CAAC;AAEF,kBAAe,OAAO,CAAC"}
@@ -1,23 +1,16 @@
1
1
  import { Compiler } from "webpack";
2
- import type { PackageJson } from "type-fest";
2
+ /**
3
+ * Webpack plugin to move files into the output directory after the build.
4
+ * This is useful for moving files like README.md, CHANGELOG.md, etc. into the dist folder.
5
+ * Also, it can transform the package.json file before writing it to the output directory (by default, it modifies it inplace).
6
+ */
3
7
  export interface MoveFilesIntoDistFolderPluginOptions {
4
- /**
5
- * A function that accepts the original package.json content and returns the modified version.
6
- */
7
- transform?: (packageJson: PackageJson) => PackageJson;
8
- /**
9
- * Optionally override the path to the package.json file.
10
- */
8
+ transform?: (packageJson: any) => any;
11
9
  packageJsonPath?: string;
12
- /**
13
- * An array of additional file paths (relative to the project root) to be moved into the dist folder.
14
- * Defaults to ["CHANGELOG.md", "README.md"].
15
- */
16
10
  files?: string[];
17
11
  }
18
- declare class MoveFilesIntoDistFolderPlugin {
12
+ export declare class MoveFilesIntoDistFolderPlugin {
19
13
  private options;
20
14
  constructor(options?: MoveFilesIntoDistFolderPluginOptions);
21
15
  apply(compiler: Compiler): void;
22
16
  }
23
- export default MoveFilesIntoDistFolderPlugin;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MoveFilesIntoDistFolderPlugin = void 0;
3
4
  const tslib_1 = require("tslib");
4
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
5
+ const fs_1 = require("fs");
5
6
  const path_1 = tslib_1.__importDefault(require("path"));
6
7
  class MoveFilesIntoDistFolderPlugin {
7
8
  options;
@@ -15,19 +16,26 @@ class MoveFilesIntoDistFolderPlugin {
15
16
  if (!outputPath) {
16
17
  throw new Error("Output path is not defined in webpack configuration.");
17
18
  }
18
- // Resolve the package.json file (allowing an override via options)
19
+ const projectRoot = compiler.context;
19
20
  const pkgPath = this.options.packageJsonPath
20
- ? path_1.default.resolve(compiler.context, this.options.packageJsonPath)
21
- : path_1.default.resolve(compiler.context, "package.json");
22
- // Read the original package.json
23
- const packageJson = await fs_extra_1.default.readJson(pkgPath);
24
- // Apply the user provided transform if available
21
+ ? path_1.default.resolve(projectRoot, this.options.packageJsonPath)
22
+ : path_1.default.resolve(projectRoot, "package.json");
23
+ // Read & transform package.json (overwriting in root)
24
+ const packageJsonRaw = await fs_1.promises.readFile(pkgPath, "utf-8");
25
+ const packageJson = JSON.parse(packageJsonRaw);
25
26
  const transformedPackageJson = this.options.transform
26
27
  ? this.options.transform(packageJson)
27
28
  : packageJson;
28
- // Write the modified package.json to the output folder (e.g., dist)
29
- await fs_extra_1.default.writeJson(pkgPath, transformedPackageJson, { spaces: 2 });
30
- // Determine the additional files to move, defaulting to ["CHANGELOG.md", "README.md"]
29
+ // Capture trailing whitespace from the original file.
30
+ const trailingWhitespaceMatch = packageJsonRaw.match(/(\s*)$/);
31
+ const trailingWhitespace = trailingWhitespaceMatch
32
+ ? trailingWhitespaceMatch[1]
33
+ : "";
34
+ // Overwrite package.json in the root project, preserving trailing whitespace if it had it.
35
+ const newPackageJsonContent = JSON.stringify(transformedPackageJson, null, 2) +
36
+ trailingWhitespace;
37
+ await fs_1.promises.writeFile(pkgPath, newPackageJsonContent);
38
+ // Move additional files (defaults: CHANGELOG.md, README.md)
31
39
  const filesToMove = this.options.files || [
32
40
  "CHANGELOG.md",
33
41
  "README.md",
@@ -36,8 +44,12 @@ class MoveFilesIntoDistFolderPlugin {
36
44
  await Promise.all(filesToMove.map(async (fileName) => {
37
45
  const sourcePath = path_1.default.resolve(compiler.context, fileName);
38
46
  const destFilePath = path_1.default.join(outputPath, fileName);
39
- if (await fs_extra_1.default.pathExists(sourcePath)) {
40
- await fs_extra_1.default.copy(sourcePath, destFilePath);
47
+ try {
48
+ await fs_1.promises.copyFile(sourcePath, destFilePath);
49
+ }
50
+ catch (err) {
51
+ if (err.code !== "ENOENT")
52
+ throw err; // Ignore missing files
41
53
  }
42
54
  }));
43
55
  }
@@ -47,5 +59,5 @@ class MoveFilesIntoDistFolderPlugin {
47
59
  });
48
60
  }
49
61
  }
50
- exports.default = MoveFilesIntoDistFolderPlugin;
62
+ exports.MoveFilesIntoDistFolderPlugin = MoveFilesIntoDistFolderPlugin;
51
63
  //# sourceMappingURL=MoveFilesIntoDistFolderPlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MoveFilesIntoDistFolderPlugin.js","sourceRoot":"","sources":["../../src/plugins/MoveFilesIntoDistFolderPlugin.ts"],"names":[],"mappings":";;;AACA,gEAA0B;AAC1B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f,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;oBACjC,MAAM,UAAU,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;oBAC5D,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;oBACrD,IAAI;wBACF,MAAM,aAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;qBAC7C;oBAAC,OAAO,GAAQ,EAAE;wBACjB,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;4BAAE,MAAM,GAAG,CAAC,CAAC,uBAAuB;qBAC9D;gBACH,CAAC,CAAC,CACH,CAAC;aACH;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;aACjE;QACH,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAnED,sEAmEC"}
@@ -1,10 +1,16 @@
1
1
  import { Compiler } from "webpack";
2
+ /**
3
+ * Options for the UseClientInjectionPlugin.
4
+ */
2
5
  export interface UseClientInjectionPluginOptions {
3
6
  /**
4
7
  * The source file to check for 'use client'. Defaults to 'src/index.ts'.
5
8
  */
6
9
  sourceFile?: string;
7
10
  }
11
+ /**
12
+ * A Webpack plugin that injects 'use client'; at the beginning of the asset if the original file contains 'use client' at first line.
13
+ */
8
14
  declare class UseClientInjectionPlugin {
9
15
  private options;
10
16
  private shouldInject;
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UseClientInjectionPlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const webpack_sources_1 = require("webpack-sources");
6
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
5
+ const fs_1 = require("fs");
7
6
  const path_1 = tslib_1.__importDefault(require("path"));
7
+ /**
8
+ * A Webpack plugin that injects 'use client'; at the beginning of the asset if the original file contains 'use client' at first line.
9
+ */
8
10
  class UseClientInjectionPlugin {
9
11
  options;
10
12
  shouldInject = false; // flag determining if injection should occur
@@ -12,18 +14,14 @@ class UseClientInjectionPlugin {
12
14
  this.options = options;
13
15
  }
14
16
  apply(compiler) {
15
- // Resolve the source file path based on the provided option or default to 'src/index.ts' for components
16
17
  const sourceFilePath = this.options.sourceFile
17
18
  ? path_1.default.resolve(compiler.context, this.options.sourceFile)
18
19
  : path_1.default.resolve(compiler.context, "src/index.ts");
19
20
  // Read the source file and check if its first non-empty line contains 'use client'
20
- if (fs_extra_1.default.existsSync(sourceFilePath)) {
21
+ if ((0, fs_1.existsSync)(sourceFilePath)) {
21
22
  try {
22
- const fileContent = fs_extra_1.default.readFileSync(sourceFilePath, "utf8");
23
- const firstLine = fileContent
24
- .split("\n")
25
- .find((line) => line.trim() !== "")
26
- ?.trim();
23
+ const fileContent = (0, fs_1.readFileSync)(sourceFilePath, "utf8");
24
+ const firstLine = fileContent.split("\n")[0].trim();
27
25
  if (firstLine === `"use client";` || firstLine === `'use client';`) {
28
26
  this.shouldInject = true;
29
27
  }
@@ -32,27 +30,28 @@ class UseClientInjectionPlugin {
32
30
  console.error(`Error reading ${sourceFilePath}:`, err);
33
31
  }
34
32
  }
35
- // Hook into the emit process of webpack
33
+ // Use the emit hook to modify assets before they are emitted.
36
34
  compiler.hooks.emit.tapAsync("UseClientInjectionPlugin", (compilation, callback) => {
37
35
  if (!this.shouldInject) {
38
- // Skip injecting if the source file didn't include "use client"
39
- callback();
40
- return;
36
+ return callback();
41
37
  }
38
+ // Get RawSource from the webpack sources available in the compiler
39
+ const { RawSource } = compiler.webpack.sources;
42
40
  Object.keys(compilation.assets).forEach((assetName) => {
43
41
  if (assetName.endsWith(".js")) {
44
- const asset = compilation.assets[assetName];
45
- let source = asset.source().toString();
46
- // Only inject if it's not already present
47
- if (!source.startsWith(`"use client";`) &&
48
- !source.startsWith(`'use client';`)) {
42
+ let source = compilation.assets[assetName].source().toString();
43
+ if (!source.startsWith('"use client";') &&
44
+ !source.startsWith("'use client';")) {
49
45
  source = `"use client";\n${source}`;
50
- compilation.assets[assetName] = new webpack_sources_1.RawSource(source);
51
- console.log(`Injected "use client" declarative in: ${assetName}`);
46
+ // Replace the asset with a new instance of RawSource. In the future we can improve this using the new Webpack 5 API,
47
+ // but after a few tests it doesn't seem to work in the current architecture, it just doesn't update the asset at all.
48
+ // eslint-disable-next-line no-param-reassign
49
+ compilation.assets[assetName] = new RawSource(source);
50
+ console.log(`Injected "use client" in: ${assetName}`);
52
51
  }
53
52
  }
54
53
  });
55
- callback();
54
+ return callback();
56
55
  });
57
56
  }
58
57
  }
@@ -1 +1 @@
1
- {"version":3,"file":"UseClientInjectionPlugin.js","sourceRoot":"","sources":["../../src/plugins/UseClientInjectionPlugin.ts"],"names":[],"mappings":";;;;AAEA,qDAA4C;AAC5C,gEAA0B;AAC1B,wDAAwB;AASxB,MAAM,wBAAwB;IACpB,OAAO,CAAkC;IACzC,YAAY,GAAY,KAAK,CAAC,CAAC,6CAA6C;IAEpF,YAAY,UAA2C,EAAE;QACvD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAkB;QACtB,wGAAwG;QACxG,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU;YAC5C,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YACzD,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;QAEnD,mFAAmF;QACnF,IAAI,kBAAE,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE;YACjC,IAAI;gBACF,MAAM,WAAW,GAAG,kBAAE,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;gBAC5D,MAAM,SAAS,GAAG,WAAW;qBAC1B,KAAK,CAAC,IAAI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CAAC,WAAW,EAAE,QAAQ,EAAE,EAAE;YACxB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;gBACtB,OAAO,QAAQ,EAAE,CAAC;aACnB;YAED,mEAAmE;YACnE,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC;YAE/C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;gBACpD,IAAI,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;oBAC7B,IAAI,MAAM,GAAG,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;oBAE/D,IACE,CAAC,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC;wBACnC,CAAC,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,EACnC;wBACA,MAAM,GAAG,kBAAkB,MAAM,EAAE,CAAC;wBAEpC,qHAAqH;wBACrH,sHAAsH;wBACtH,6CAA6C;wBAC7C,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,SAAS,CAAC,MAAM,CAAC,CAAC;wBACtD,OAAO,CAAC,GAAG,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;qBACvD;iBACF;YACH,CAAC,CAAC,CAAC;YAEH,OAAO,QAAQ,EAAE,CAAC;QACpB,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAEQ,4DAAwB"}
@@ -5,3 +5,6 @@ export { cssMinimizerPlugin } from "./cssMinimizerPlugin";
5
5
  export { terserJSPlugin } from "./terserJSPlugin";
6
6
  export { dtsBundleGeneratorPlugin } from "./dtsBundleGeneratorPlugin";
7
7
  export { UseClientInjectionPlugin } from "./UseClientInjectionPlugin";
8
+ export { MoveFilesIntoDistFolderPlugin } from "./MoveFilesIntoDistFolderPlugin";
9
+ export type { MoveFilesIntoDistFolderPluginOptions } from "./MoveFilesIntoDistFolderPlugin";
10
+ export type { UseClientInjectionPluginOptions } from "./UseClientInjectionPlugin";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UseClientInjectionPlugin = exports.dtsBundleGeneratorPlugin = exports.terserJSPlugin = exports.cssMinimizerPlugin = exports.cssHashRemoverPlugin = exports.vanillaExtractPlugin = exports.miniCssExtractPlugin = void 0;
3
+ exports.MoveFilesIntoDistFolderPlugin = exports.UseClientInjectionPlugin = exports.dtsBundleGeneratorPlugin = exports.terserJSPlugin = exports.cssMinimizerPlugin = exports.cssHashRemoverPlugin = exports.vanillaExtractPlugin = exports.miniCssExtractPlugin = void 0;
4
4
  var miniCssExtract_1 = require("./miniCssExtract");
5
5
  Object.defineProperty(exports, "miniCssExtractPlugin", { enumerable: true, get: function () { return miniCssExtract_1.miniCssExtractPlugin; } });
6
6
  var vanillaExtractPlugin_1 = require("./vanillaExtractPlugin");
@@ -15,4 +15,6 @@ var dtsBundleGeneratorPlugin_1 = require("./dtsBundleGeneratorPlugin");
15
15
  Object.defineProperty(exports, "dtsBundleGeneratorPlugin", { enumerable: true, get: function () { return dtsBundleGeneratorPlugin_1.dtsBundleGeneratorPlugin; } });
16
16
  var UseClientInjectionPlugin_1 = require("./UseClientInjectionPlugin");
17
17
  Object.defineProperty(exports, "UseClientInjectionPlugin", { enumerable: true, get: function () { return UseClientInjectionPlugin_1.UseClientInjectionPlugin; } });
18
+ var MoveFilesIntoDistFolderPlugin_1 = require("./MoveFilesIntoDistFolderPlugin");
19
+ Object.defineProperty(exports, "MoveFilesIntoDistFolderPlugin", { enumerable: true, get: function () { return MoveFilesIntoDistFolderPlugin_1.MoveFilesIntoDistFolderPlugin; } });
18
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwD;AAA/C,sHAAA,oBAAoB,OAAA;AAC7B,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":";;;AAAA,mDAAwD;AAA/C,sHAAA,oBAAoB,OAAA;AAC7B,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA;AAC7B,2DAA0D;AAAjD,wHAAA,kBAAkB,OAAA;AAC3B,mDAAkD;AAAzC,gHAAA,cAAc,OAAA;AACvB,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AACjC,iFAAgF;AAAvE,8IAAA,6BAA6B,OAAA"}
@@ -1,6 +1,3 @@
1
- /**
2
- * Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
3
- */
4
1
  /// <reference types="jest" />
5
2
  export declare const arrayFilterEmpty: (array: {
6
3
  test: RegExp;
@@ -13,3 +10,11 @@ export declare const arrayFilterEmpty: (array: {
13
10
  use?: any;
14
11
  exclude?: RegExp | undefined;
15
12
  }[];
13
+ export declare const getComponentsPackageExports: (baseDir: string, folders: string[]) => {
14
+ packageExports: Record<string, {
15
+ import: string;
16
+ require: string;
17
+ }>;
18
+ dtsCommands: string[];
19
+ webpackEntries: Record<string, string>;
20
+ };
@@ -1,9 +1,61 @@
1
1
  "use strict";
2
- /**
3
- * Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
4
- */
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.arrayFilterEmpty = void 0;
3
+ exports.getComponentsPackageExports = exports.arrayFilterEmpty = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
6
+ const fs_1 = require("fs");
7
+ const constants_1 = require("./constants");
7
8
  const arrayFilterEmpty = (array) => array.filter((x) => !!x);
8
9
  exports.arrayFilterEmpty = arrayFilterEmpty;
10
+ /**
11
+ * Retrieves all subdirectories in a given list of folders.
12
+ */
13
+ const getDirectories = (baseDir, folders) => folders
14
+ .map((folder) => {
15
+ const folderPath = path_1.default.join(baseDir, folder);
16
+ if (!(0, fs_1.existsSync)(folderPath))
17
+ return [];
18
+ return (0, fs_1.readdirSync)(folderPath)
19
+ .map((subfolder) => path_1.default.join(folder, subfolder)) // Maintain relative path
20
+ .filter((subfolderPath) => (0, fs_1.statSync)(path_1.default.join(baseDir, subfolderPath)).isDirectory());
21
+ })
22
+ .flat();
23
+ const getComponentsPackageExports = (baseDir, folders) => {
24
+ const packageExports = {};
25
+ const webpackEntries = {};
26
+ const dtsCommands = [];
27
+ const allComponents = getDirectories(baseDir, folders);
28
+ // Process each component folder
29
+ allComponents.forEach((componentPath) => {
30
+ const componentName = path_1.default.basename(componentPath);
31
+ const componentDir = path_1.default.join(baseDir, componentPath);
32
+ let entryFile = path_1.default.join(componentDir, "src", "index.ts");
33
+ const extraCommands = [];
34
+ // 2. If a src/components folder exists, generate a temporary file to aggregate exports
35
+ const componentsDir = path_1.default.join(componentDir, "src", "components");
36
+ if ((0, fs_1.existsSync)(componentsDir)) {
37
+ const tempFilePath = path_1.default.join(componentDir, "src", "build-temp--index.ts");
38
+ // The temp file re-exports the main index and the sub-components
39
+ const tempContent = `
40
+ export * from "./index";
41
+ export * from "./components/index";
42
+ `;
43
+ (0, fs_1.writeFileSync)(tempFilePath, tempContent, "utf8");
44
+ entryFile = tempFilePath; // override entry to use the temp file
45
+ extraCommands.push(`&& rm ${tempFilePath}`); // Cleanup the temp file after running the DTS command
46
+ }
47
+ // 3. Build the webpack entry. Using a relative path works well with webpack.
48
+ webpackEntries[componentName] = entryFile;
49
+ // 4. Prepare the DTS bundle generator command for this component, removing the temp file after running it for cleanup
50
+ const dtsCommand = `node ${constants_1.rootDir}/node_modules/.bin/dts-bundle-generator -o ./dist/${componentName}/index.d.ts ${entryFile} ${extraCommands.join("")}`;
51
+ dtsCommands.push(dtsCommand);
52
+ // 5. Build the package exports for this component
53
+ packageExports[`./${componentName}`] = {
54
+ import: `./dist/${componentName}/index.js`,
55
+ require: `./dist/${componentName}/index.js`,
56
+ };
57
+ });
58
+ return { packageExports, dtsCommands, webpackEntries };
59
+ };
60
+ exports.getComponentsPackageExports = getComponentsPackageExports;
9
61
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEI,MAAM,gBAAgB,GAAG,CAC9B,KAKG,EACH,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAPjB,QAAA,gBAAgB,oBAOC"}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":";;;;AAAA,wDAAwB;AACxB,2BAAsE;AACtE,2CAAsC;AAE/B,MAAM,gBAAgB,GAAG,CAC9B,KAKG,EACH,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAPjB,QAAA,gBAAgB,oBAOC;AAE9B;;GAEG;AACH,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,OAAiB,EAAE,EAAE,CAC5D,OAAO;KACJ,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;IACd,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9C,IAAI,CAAC,IAAA,eAAU,EAAC,UAAU,CAA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AAM,WAAW,GAAG;;;KAGrB,CAAC;YACA,IAAA,kBAAa,EAAC,YAAY,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;YAEjD,SAAS,GAAG,YAAY,CAAC,CAAC,sCAAsC;YAEhE,aAAa,CAAC,IAAI,CAAC,SAAS,YAAY,EAAE,CAAC,CAAC,CAAC,sDAAsD;SACpG;QAED,6EAA6E;QAC7E,cAAc,CAAC,aAAa,CAAC,GAAG,SAAS,CAAC;QAE1C,sHAAsH;QACtH,MAAM,UAAU,GAAG,QAAQ,mBAAO,qDAAqD,aAAa,eAAe,SAAS,IAAI,aAAa,CAAC,IAAI,CAChJ,EAAE,CACH,EAAE,CAAC;QACJ,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE7B,kDAAkD;QAClD,cAAc,CAAC,KAAK,aAAa,EAAE,CAAC,GAAG;YACrC,MAAM,EAAE,UAAU,aAAa,WAAW;YAC1C,OAAO,EAAE,UAAU,aAAa,WAAW;SAC5C,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,CAAC;AACzD,CAAC,CAAC;AAzDW,QAAA,2BAA2B,+BAyDtC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./constants";
2
2
  export * from "./helpers";
3
+ export * from "./types";
@@ -3,4 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./constants"), exports);
5
5
  tslib_1.__exportStar(require("./helpers"), exports);
6
+ tslib_1.__exportStar(require("./types"), exports);
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,oDAA0B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,oDAA0B;AAC1B,kDAAwB"}
@@ -0,0 +1,8 @@
1
+ import { MoveFilesIntoDistFolderPluginOptions, UseClientInjectionPluginOptions } from "../plugins";
2
+ export type WebpackBaseConfig = {
3
+ dtsBundleConfig?: {
4
+ entries: string[];
5
+ };
6
+ packageJsonConfig?: MoveFilesIntoDistFolderPluginOptions;
7
+ useClientInjectionOptions?: UseClientInjectionPluginOptions;
8
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/utils/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimbus-ds/webpack",
3
- "version": "1.5.0-rc.2",
3
+ "version": "1.5.0-rc.4",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -24,7 +24,6 @@
24
24
  "devDependencies": {
25
25
  "@types/dashify": "^1.0.1",
26
26
  "@types/webpack": "^5.28.0",
27
- "@types/webpack-sources": "^3",
28
27
  "@vanilla-extract/webpack-plugin": "^2.3.1",
29
28
  "css-minimizer-webpack-plugin": "^4.2.2",
30
29
  "dashify": "^2.0.0",
@@ -33,8 +32,7 @@
33
32
  "typescript": "^4.9.3",
34
33
  "webpack": "^5.76.0",
35
34
  "webpack-merge": "^5.8.0",
36
- "webpack-shell-plugin-next": "^2.3.1",
37
- "webpack-sources": "^3.2.3"
35
+ "webpack-shell-plugin-next": "^2.3.1"
38
36
  },
39
37
  "stableVersion": "1.4.0"
40
38
  }
@@ -1,15 +0,0 @@
1
- import { Compiler } from "webpack";
2
- export interface CleanupTempFilesPluginOptions {
3
- pattern?: string;
4
- /**
5
- * The base directory to search in.
6
- * Defaults to the "src" directory inside the webpack context.
7
- */
8
- baseDir?: string;
9
- }
10
- declare class CleanupTempFilesPlugin {
11
- private options;
12
- constructor(options?: CleanupTempFilesPluginOptions);
13
- apply(compiler: Compiler): void;
14
- }
15
- export default CleanupTempFilesPlugin;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
5
- const path_1 = tslib_1.__importDefault(require("path"));
6
- const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
7
- class CleanupTempFilesPlugin {
8
- options;
9
- constructor(options = {}) {
10
- this.options = options;
11
- }
12
- apply(compiler) {
13
- compiler.hooks.done.tapPromise("CleanupTempFilesPlugin", async () => {
14
- // Use the webpack config's context as the project root.
15
- const projectContext = compiler.options.context || compiler.context;
16
- // Determine the search directory: if baseDir is provided, resolve it relative to the project context,
17
- // otherwise default to the "src" folder inside the project.
18
- const searchDir = this.options.baseDir
19
- ? path_1.default.resolve(projectContext, this.options.baseDir)
20
- : path_1.default.resolve(projectContext, "src");
21
- console.warn("CLEANUP TEMP FILES PLUGIN USING SEARCHDIR => ", searchDir);
22
- // Use the provided pattern or default to "**/build-temp--index.ts"
23
- const pattern = this.options.pattern || "**/build-temp--index.ts";
24
- try {
25
- const tempFiles = await (0, fast_glob_1.default)(pattern, { cwd: searchDir });
26
- if (tempFiles.length === 0) {
27
- // No temporary files found, just skip the removal
28
- return;
29
- }
30
- await Promise.all(tempFiles.map(async (relativeFilePath) => {
31
- const absoluteFilePath = path_1.default.join(searchDir, relativeFilePath);
32
- if (await fs_extra_1.default.pathExists(absoluteFilePath)) {
33
- await fs_extra_1.default.remove(absoluteFilePath);
34
- console.log(`Removed temporary file: ${absoluteFilePath}`);
35
- }
36
- }));
37
- }
38
- catch (error) {
39
- console.error("Error cleaning up temporary files:", error);
40
- }
41
- });
42
- }
43
- }
44
- exports.default = CleanupTempFilesPlugin;
45
- //# sourceMappingURL=CleanupTempFilesPlugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"CleanupTempFilesPlugin.js","sourceR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