@nimbus-ds/webpack 1.4.0 → 1.5.0-rc.1

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,4 +1,10 @@
1
1
  import { Configuration } from "webpack";
2
- export declare const getConfiguration: (config?: Configuration) => Configuration;
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;
3
9
  declare const _default: Configuration;
4
10
  export default _default;
@@ -13,29 +13,42 @@ 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 webpack = {
16
+ const MoveFilesIntoDistFolderPlugin_1 = tslib_1.__importDefault(require("../plugins/MoveFilesIntoDistFolderPlugin"));
17
+ const webpack = (dtsBundleConfig, packageJsonConfig) => ({
17
18
  target: "node",
18
19
  mode: utils_1.isProduction ? "production" : "development",
19
20
  entry: {
20
21
  "./index": "./src/index.ts",
21
22
  },
22
23
  output: {
23
- filename: "[name].js",
24
+ filename: (pathData) => {
25
+ return pathData.chunk?.name === "./index"
26
+ ? "[name].js"
27
+ : "[name]/index.js";
28
+ },
29
+ library: {
30
+ name: ["@nimbus-ds", "[name]"],
31
+ type: "umd",
32
+ },
24
33
  libraryTarget: "umd",
25
34
  },
26
35
  module: {
27
36
  rules: (0, utils_1.arrayFilterEmpty)([rules_1.typescriptRule, rules_1.svgRule]),
28
37
  },
29
- plugins: [(0, plugins_1.dtsBundleGeneratorPlugin)()],
38
+ plugins: [
39
+ (0, plugins_1.dtsBundleGeneratorPlugin)(dtsBundleConfig),
40
+ new MoveFilesIntoDistFolderPlugin_1.default(packageJsonConfig),
41
+ new plugins_1.UseClientInjectionPlugin(),
42
+ ],
30
43
  resolve: {
31
44
  alias: alias_1.aliasItems,
32
45
  extensions: [".tsx", ".ts", ".js"],
33
46
  },
34
47
  externals: external_1.externalItems,
35
- };
36
- const getConfiguration = (config) => utils_1.isProduction
37
- ? (0, webpack_merge_1.default)(webpack, production_1.default, config || {})
38
- : (0, webpack_merge_1.default)(webpack, development_1.default, config || {});
48
+ });
49
+ const getConfiguration = (config, extraParams) => utils_1.isProduction
50
+ ? (0, webpack_merge_1.default)(webpack(extraParams?.dtsBundleConfig, extraParams?.packageJsonConfig), production_1.default, config || {})
51
+ : (0, webpack_merge_1.default)(webpack(), development_1.default, config || {});
39
52
  exports.getConfiguration = getConfiguration;
40
53
  exports.default = (0, exports.getConfiguration)();
41
54
  //# sourceMappingURL=base.js.map
@@ -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,wCAAsD;AACtD,mCAAqC;AACrC,yCAA2C;AAE3C,sEAAsC;AACtC,wEAAwC;AAExC,MAAM,OAAO,GAAkB;IAC7B,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,WAAW;QACrB,aAAa,EAAE,KAAK;KACrB;IACD,MAAM,EAAE;QACN,KAAK,EAAE,IAAA,wBAAgB,EAAC,CAAC,sBAAc,EAAE,eAAO,CAAC,CAAC;KACnD;IACD,OAAO,EAAE,CAAC,IAAA,kCAAwB,GAAE,CAAC;IACrC,OAAO,EAAE;QACP,KAAK,EAAE,kBAAU;QACjB,UAAU,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC;KACnC;IACD,SAAS,EAAE,wBAAa;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,IAAI,uCAA6B,CAAC,iBAAiB,CAAC;QACpD,IAAI,kCAAwB,EAAE;KAC/B;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,WAGC,EACD,EAAE,CACF,oBAAY;IACV,CAAC,CAAC,IAAA,uBAAK,EACH,OAAO,CAAC,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,iBAAiB,CAAC,EACrE,oBAAU,EACV,MAAM,IAAI,EAAE,CACb;IACH,CAAC,CAAC,IAAA,uBAAK,EAAC,OAAO,EAAE,EAAE,qBAAW,EAAE,MAAM,IAAI,EAAE,CAAC,CAAC;AAbrC,QAAA,gBAAgB,oBAaqB;AAElD,kBAAe,IAAA,wBAAgB,GAAE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { UseClientInjectionPlugin } from "./plugins";
2
+ import MoveFilesIntoDistFolderPlugin from "./plugins/MoveFilesIntoDistFolderPlugin";
1
3
  export declare const rules: {
2
4
  cssLoaderExtractRule: {
3
5
  test: RegExp;
@@ -35,6 +37,8 @@ export declare const plugins: {
35
37
  dtsBundleGeneratorPlugin: (configuration?: {
36
38
  entries: string[];
37
39
  }) => import("webpack-shell-plugin-next").default;
40
+ UseClientInjectionPlugin: typeof UseClientInjectionPlugin;
41
+ MoveFilesIntoDistFolderPlugin: typeof MoveFilesIntoDistFolderPlugin;
38
42
  };
39
43
  export declare const configuration: {
40
44
  aliasItems: {
@@ -53,7 +57,12 @@ export declare const configuration: {
53
57
  development: import("webpack").Configuration;
54
58
  production: import("webpack").Configuration;
55
59
  base: import("webpack").Configuration;
56
- getConfiguration: (config?: import("webpack").Configuration | undefined) => 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;
57
66
  };
58
67
  export declare const utils: {
59
68
  rootDir: string;
@@ -109,6 +118,8 @@ declare const webpack: {
109
118
  dtsBundleGeneratorPlugin: (configuration?: {
110
119
  entries: string[];
111
120
  }) => import("webpack-shell-plugin-next").default;
121
+ UseClientInjectionPlugin: typeof UseClientInjectionPlugin;
122
+ MoveFilesIntoDistFolderPlugin: typeof MoveFilesIntoDistFolderPlugin;
112
123
  };
113
124
  configuration: {
114
125
  aliasItems: {
@@ -127,7 +138,12 @@ declare const webpack: {
127
138
  development: import("webpack").Configuration;
128
139
  production: import("webpack").Configuration;
129
140
  base: import("webpack").Configuration;
130
- getConfiguration: (config?: import("webpack").Configuration | undefined) => 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;
131
147
  };
132
148
  utils: {
133
149
  rootDir: string;
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
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");
4
5
  const config_1 = require("./config");
5
6
  const plugins_1 = require("./plugins");
7
+ const MoveFilesIntoDistFolderPlugin_1 = tslib_1.__importDefault(require("./plugins/MoveFilesIntoDistFolderPlugin"));
6
8
  const rules_1 = require("./rules");
7
9
  const utils_1 = require("./utils");
8
10
  exports.rules = {
@@ -18,6 +20,8 @@ exports.plugins = {
18
20
  cssHashRemoverPlugin: plugins_1.cssHashRemoverPlugin,
19
21
  cssMinimizerPlugin: plugins_1.cssMinimizerPlugin,
20
22
  dtsBundleGeneratorPlugin: plugins_1.dtsBundleGeneratorPlugin,
23
+ UseClientInjectionPlugin: plugins_1.UseClientInjectionPlugin,
24
+ MoveFilesIntoDistFolderPlugin: MoveFilesIntoDistFolderPlugin_1.default
21
25
  };
22
26
  exports.configuration = {
23
27
  aliasItems: config_1.aliasItems,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAOkB;AAClB,uCAMmB;AACnB,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;CACzB,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,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"}
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,45 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CleanupTempFilesPlugin.js","sourceRoot":"","sources":["../../src/plugins/CleanupTempFilesPlugin.ts"],"names":[],"mappings":";;;AAEA,gEAA0B;AAC1B,wDAAwB;AACxB,kEAAiC;AAYjC,MAAM,sBAAsB;IAClB,OAAO,CAAgC;IAE/C,YAAY,UAAyC,EAAE;QACrD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAkB;QACtB,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,wBAAwB,EAAE,KAAK,IAAI,EAAE;YAClE,wDAAwD;YACxD,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC;YACpE,sGAAsG;YACtG,4DAA4D;YAC5D,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO;gBACpC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,cAAc,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;gBACpD,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;YAExC,OAAO,CAAC,IAAI,CAAC,+CAA+C,EAAE,SAAS,CAAC,CAAC;YAEzE,mEAAmE;YACnE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,yBAAyB,CAAC;YAElE,IAAI;gBACF,MAAM,SAAS,GAAG,MAAM,IAAA,mBAAQ,EAAC,OAAO,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAC;gBAE9D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;oBAC1B,kDAAkD;oBAClD,OAAO;iBACR;gBAED,MAAM,OAAO,CAAC,GAAG,CACf,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,EAAE;oBACvC,MAAM,gBAAgB,GAAG,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;oBAChE,IAAI,MAAM,kBAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,EAAE;wBACzC,MAAM,kBAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;wBAClC,OAAO,CAAC,GAAG,CAAC,2BAA2B,gBAAgB,EAAE,CAAC,CAAC;qBAC5D;gBACH,CAAC,CAAC,CACH,CAAC;aACH;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;aAC5D;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,kBAAe,sBAAsB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Compiler } from "webpack";
2
+ import type { PackageJson } from "type-fest";
3
+ 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
+ */
11
+ 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
+ files?: string[];
17
+ }
18
+ declare class MoveFilesIntoDistFolderPlugin {
19
+ private options;
20
+ constructor(options?: MoveFilesIntoDistFolderPluginOptions);
21
+ apply(compiler: Compiler): void;
22
+ }
23
+ export default MoveFilesIntoDistFolderPlugin;
@@ -0,0 +1,50 @@
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
+ class MoveFilesIntoDistFolderPlugin {
7
+ options;
8
+ constructor(options = {}) {
9
+ this.options = options;
10
+ }
11
+ apply(compiler) {
12
+ compiler.hooks.afterEmit.tapPromise("MoveFilesIntoDistFolderPlugin", async () => {
13
+ try {
14
+ const outputPath = compiler.options.output.path;
15
+ if (!outputPath) {
16
+ throw new Error("Output path is not defined in webpack configuration.");
17
+ }
18
+ // Resolve the package.json file (allowing an override via options)
19
+ 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
25
+ let transformedPackageJson = this.options.transform
26
+ ? this.options.transform(packageJson)
27
+ : 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"]
31
+ const filesToMove = this.options.files || [
32
+ "CHANGELOG.md",
33
+ "README.md",
34
+ ];
35
+ await Promise.all(filesToMove.map(async (fileName) => {
36
+ const sourcePath = path_1.default.resolve(compiler.context, fileName);
37
+ const destFilePath = path_1.default.join(outputPath, fileName);
38
+ if (await fs_extra_1.default.pathExists(sourcePath)) {
39
+ await fs_extra_1.default.copy(sourcePath, destFilePath);
40
+ }
41
+ }));
42
+ }
43
+ catch (error) {
44
+ console.error("Error in MoveFilesIntoDistFolderPlugin:", error);
45
+ }
46
+ });
47
+ }
48
+ }
49
+ exports.default = MoveFilesIntoDistFolderPlugin;
50
+ //# sourceMappingURL=MoveFilesIntoDistFolderPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MoveFilesIntoDistFolderPlugin.js","sourceRoot":"","sources":["../../src/plugins/MoveFilesIntoDistFolderPlugin.ts"],"names":[],"mappings":";;;AACA,gEAA0B;AAC1B,wDAAwB;AAmBxB,MAAM,6BAA6B;IACzB,OAAO,CAAuC;IAEtD,YAAY,UAAgD,EAAE;QAC5D,IAAI,CA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C,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;oBAC5D,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;oBACrD,IAAI,MAAM,kBAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE;wBACnC,MAAM,kBAAE,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;qBACzC;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;AAED,kBAAe,6BAA6B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Compiler } from "webpack";
2
+ export interface UseClientInjectionPluginOptions {
3
+ /**
4
+ * The source file to check for 'use client'. Defaults to 'src/index.ts'.
5
+ */
6
+ sourceFile?: string;
7
+ }
8
+ declare class UseClientInjectionPlugin {
9
+ private options;
10
+ private shouldInject;
11
+ constructor(options?: UseClientInjectionPluginOptions);
12
+ apply(compiler: Compiler): void;
13
+ }
14
+ export { UseClientInjectionPlugin };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UseClientInjectionPlugin = void 0;
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"));
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
+ class UseClientInjectionPlugin {
9
+ options;
10
+ shouldInject = false; // flag determining if injection should occur
11
+ constructor(options = {}) {
12
+ this.options = options;
13
+ }
14
+ apply(compiler) {
15
+ // Resolve the source file path based on the provided option or default to 'src/index.ts' for components
16
+ const sourceFilePath = this.options.sourceFile
17
+ ? path_1.default.resolve(compiler.context, this.options.sourceFile)
18
+ : path_1.default.resolve(compiler.context, "src/index.ts");
19
+ // Read the source file and check if its first non-empty line contains 'use client'
20
+ if (fs_extra_1.default.existsSync(sourceFilePath)) {
21
+ 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();
27
+ if (firstLine === `"use client";` || firstLine === `'use client';`) {
28
+ this.shouldInject = true;
29
+ }
30
+ }
31
+ catch (err) {
32
+ console.error(`Error reading ${sourceFilePath}:`, err);
33
+ }
34
+ }
35
+ // Hook into the emit process of webpack
36
+ compiler.hooks.emit.tapAsync("UseClientInjectionPlugin", (compilation, callback) => {
37
+ if (!this.shouldInject) {
38
+ // Skip injecting if the source file didn't include "use client"
39
+ callback();
40
+ return;
41
+ }
42
+ Object.keys(compilation.assets).forEach((assetName) => {
43
+ 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';`)) {
49
+ source = `"use client";\n${source}`;
50
+ compilation.assets[assetName] = new webpack_sources_1.RawSource(source);
51
+ console.log(`Injected "use client" in: ${assetName}`);
52
+ }
53
+ }
54
+ });
55
+ callback();
56
+ });
57
+ }
58
+ }
59
+ exports.UseClientInjectionPlugin = UseClientInjectionPlugin;
60
+ //# sourceMappingURL=UseClientInjectionPlugin.js.map
@@ -0,0 +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;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,GAAG,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBAC5C,IAAI,MAAM,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC;oBAEvC,0CAA0C;oBAC1C,IACE,CAAC,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC;wBACnC,CAAC,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,EACnC;wBACA,MAAM,GAAG,kBAAkB,MAAM,EAAE,CAAC;wBACpC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,2BAAS,CAAC,MAAM,CAAQ,CAAC;wBAC7D,OAAO,CAAC,GAAG,CAAC,6BAA6B,SAAS,EAAE,CAAC,CAAC;qBACvD;iBACF;YACH,CAAC,CAAC,CAAC;YACH,QAAQ,EAAE,CAAC;QACb,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAEQ,4DAAwB"}
@@ -4,3 +4,4 @@ export { cssHashRemoverPlugin } from "./cssHashRemoverPlugin";
4
4
  export { cssMinimizerPlugin } from "./cssMinimizerPlugin";
5
5
  export { terserJSPlugin } from "./terserJSPlugin";
6
6
  export { dtsBundleGeneratorPlugin } from "./dtsBundleGeneratorPlugin";
7
+ export { UseClientInjectionPlugin } from "./UseClientInjectionPlugin";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dtsBundleGeneratorPlugin = exports.terserJSPlugin = exports.cssMinimizerPlugin = exports.cssHashRemoverPlugin = exports.vanillaExtractPlugin = exports.miniCssExtractPlugin = void 0;
3
+ 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");
@@ -13,4 +13,6 @@ var terserJSPlugin_1 = require("./terserJSPlugin");
13
13
  Object.defineProperty(exports, "terserJSPlugin", { enumerable: true, get: function () { return terserJSPlugin_1.terserJSPlugin; } });
14
14
  var dtsBundleGeneratorPlugin_1 = require("./dtsBundleGeneratorPlugin");
15
15
  Object.defineProperty(exports, "dtsBundleGeneratorPlugin", { enumerable: true, get: function () { return dtsBundleGeneratorPlugin_1.dtsBundleGeneratorPlugin; } });
16
+ var UseClientInjectionPlugin_1 = require("./UseClientInjectionPlugin");
17
+ Object.defineProperty(exports, "UseClientInjectionPlugin", { enumerable: true, get: function () { return UseClientInjectionPlugin_1.UseClientInjectionPlugin; } });
16
18
  //# 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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nimbus-ds/webpack",
3
- "version": "1.4.0",
3
+ "version": "1.5.0-rc.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -24,6 +24,7 @@
24
24
  "devDependencies": {
25
25
  "@types/dashify": "^1.0.1",
26
26
  "@types/webpack": "^5.28.0",
27
+ "@types/webpack-sources": "^3",
27
28
  "@vanilla-extract/webpack-plugin": "^2.3.1",
28
29
  "css-minimizer-webpack-plugin": "^4.2.2",
29
30
  "dashify": "^2.0.0",
@@ -32,6 +33,8 @@
32
33
  "typescript": "^4.9.3",
33
34
  "webpack": "^5.76.0",
34
35
  "webpack-merge": "^5.8.0",
35
- "webpack-shell-plugin-next": "^2.3.1"
36
- }
36
+ "webpack-shell-plugin-next": "^2.3.1",
37
+ "webpack-sources": "^3.2.3"
38
+ },
39
+ "stableVersion": "1.4.0"
37
40
  }