@nimbus-ds/webpack 1.4.1-rc.1 → 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.
- package/dist/config/base.d.ts +5 -1
- package/dist/config/base.js +19 -10
- package/dist/config/base.js.map +1 -1
- package/dist/index.d.ts +11 -2
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/CleanupTempFilesPlugin.d.ts +15 -0
- package/dist/plugins/CleanupTempFilesPlugin.js +45 -0
- package/dist/plugins/CleanupTempFilesPlugin.js.map +1 -0
- package/dist/plugins/MoveFilesIntoDistFolderPlugin.d.ts +23 -0
- package/dist/plugins/MoveFilesIntoDistFolderPlugin.js +50 -0
- package/dist/plugins/MoveFilesIntoDistFolderPlugin.js.map +1 -0
- package/dist/plugins/UseClientInjectionPlugin.d.ts +9 -0
- package/dist/plugins/UseClientInjectionPlugin.js +35 -4
- package/dist/plugins/UseClientInjectionPlugin.js.map +1 -1
- package/package.json +1 -1
package/dist/config/base.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Configuration } from "webpack";
|
|
2
|
+
import { MoveFilesIntoDistFolderPluginOptions } from "../plugins/MoveFilesIntoDistFolderPlugin";
|
|
2
3
|
export declare const getConfiguration: (config?: Configuration, extraParams?: {
|
|
3
|
-
|
|
4
|
+
dtsBundleConfig?: {
|
|
5
|
+
entries: string[];
|
|
6
|
+
};
|
|
7
|
+
packageJsonConfig?: MoveFilesIntoDistFolderPluginOptions;
|
|
4
8
|
}) => Configuration;
|
|
5
9
|
declare const _default: Configuration;
|
|
6
10
|
export default _default;
|
package/dist/config/base.js
CHANGED
|
@@ -13,33 +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
|
|
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:
|
|
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: [
|
|
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
|
-
};
|
|
48
|
+
});
|
|
36
49
|
const getConfiguration = (config, extraParams) => utils_1.isProduction
|
|
37
|
-
? (0, webpack_merge_1.default)(webpack, production_1.default, config || {}
|
|
38
|
-
|
|
39
|
-
extraParams?.isClientSide
|
|
40
|
-
? { plugins: [new plugins_1.UseClientInjectionPlugin()] }
|
|
41
|
-
: {})
|
|
42
|
-
: (0, webpack_merge_1.default)(webpack, development_1.default, config || {});
|
|
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 || {});
|
|
43
52
|
exports.getConfiguration = getConfiguration;
|
|
44
53
|
exports.default = (0, exports.getConfiguration)();
|
|
45
54
|
//# sourceMappingURL=base.js.map
|
package/dist/config/base.js.map
CHANGED
|
@@ -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;
|
|
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,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,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,4 +1,5 @@
|
|
|
1
1
|
import { UseClientInjectionPlugin } from "./plugins";
|
|
2
|
+
import MoveFilesIntoDistFolderPlugin from "./plugins/MoveFilesIntoDistFolderPlugin";
|
|
2
3
|
export declare const rules: {
|
|
3
4
|
cssLoaderExtractRule: {
|
|
4
5
|
test: RegExp;
|
|
@@ -37,6 +38,7 @@ export declare const plugins: {
|
|
|
37
38
|
entries: string[];
|
|
38
39
|
}) => import("webpack-shell-plugin-next").default;
|
|
39
40
|
UseClientInjectionPlugin: typeof UseClientInjectionPlugin;
|
|
41
|
+
MoveFilesIntoDistFolderPlugin: typeof MoveFilesIntoDistFolderPlugin;
|
|
40
42
|
};
|
|
41
43
|
export declare const configuration: {
|
|
42
44
|
aliasItems: {
|
|
@@ -56,7 +58,10 @@ export declare const configuration: {
|
|
|
56
58
|
production: import("webpack").Configuration;
|
|
57
59
|
base: import("webpack").Configuration;
|
|
58
60
|
getConfiguration: (config?: import("webpack").Configuration | undefined, extraParams?: {
|
|
59
|
-
|
|
61
|
+
dtsBundleConfig?: {
|
|
62
|
+
entries: string[];
|
|
63
|
+
} | undefined;
|
|
64
|
+
packageJsonConfig?: import("./plugins/MoveFilesIntoDistFolderPlugin").MoveFilesIntoDistFolderPluginOptions | undefined;
|
|
60
65
|
} | undefined) => import("webpack").Configuration;
|
|
61
66
|
};
|
|
62
67
|
export declare const utils: {
|
|
@@ -114,6 +119,7 @@ declare const webpack: {
|
|
|
114
119
|
entries: string[];
|
|
115
120
|
}) => import("webpack-shell-plugin-next").default;
|
|
116
121
|
UseClientInjectionPlugin: typeof UseClientInjectionPlugin;
|
|
122
|
+
MoveFilesIntoDistFolderPlugin: typeof MoveFilesIntoDistFolderPlugin;
|
|
117
123
|
};
|
|
118
124
|
configuration: {
|
|
119
125
|
aliasItems: {
|
|
@@ -133,7 +139,10 @@ declare const webpack: {
|
|
|
133
139
|
production: import("webpack").Configuration;
|
|
134
140
|
base: import("webpack").Configuration;
|
|
135
141
|
getConfiguration: (config?: import("webpack").Configuration | undefined, extraParams?: {
|
|
136
|
-
|
|
142
|
+
dtsBundleConfig?: {
|
|
143
|
+
entries: string[];
|
|
144
|
+
} | undefined;
|
|
145
|
+
packageJsonConfig?: import("./plugins/MoveFilesIntoDistFolderPlugin").MoveFilesIntoDistFolderPluginOptions | undefined;
|
|
137
146
|
} | undefined) => import("webpack").Configuration;
|
|
138
147
|
};
|
|
139
148
|
utils: {
|
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 = {
|
|
@@ -19,6 +21,7 @@ exports.plugins = {
|
|
|
19
21
|
cssMinimizerPlugin: plugins_1.cssMinimizerPlugin,
|
|
20
22
|
dtsBundleGeneratorPlugin: plugins_1.dtsBundleGeneratorPlugin,
|
|
21
23
|
UseClientInjectionPlugin: plugins_1.UseClientInjectionPlugin,
|
|
24
|
+
MoveFilesIntoDistFolderPlugin: MoveFilesIntoDistFolderPlugin_1.default
|
|
22
25
|
};
|
|
23
26
|
exports.configuration = {
|
|
24
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":"
|
|
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","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AI,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,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAkB;QACtB,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,UAAU,CACjC,+BAA+B,EAC/B,KAAK,IAAI,EAAE;YACT,IAAI;gBACF,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;gBAChD,IAAI,CAAC,UAAU,EAAE;oBACf,MAAM,IAAI,KAAK,CACb,sDAAsD,CACvD,CAAC;iBACH;gBACD,mEAAmE;gBACnE,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe;oBAC1C,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;oBAC9D,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;gBAEnD,iCAAiC;gBACjC,MAAM,WAAW,GAAgB,MAAM,kBAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;gBAE5D,iDAAiD;gBACjD,IAAI,sBAAsB,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS;oBACjD,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC;oBACrC,CAAC,CAAC,WAAW,CAAC;gBAEhB,oEAAoE;gBACpE,MAAM,kBAAE,CAAC,SAAS,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;gBAEnE,sFAAsF;gBACtF,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI;oBACxC,cAAc;oBACd,WAAW;iBACZ,CAAC;gBACF,MAAM,OAAO,CAAC,GAAG,CACf,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,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"}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
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
|
+
}
|
|
2
8
|
declare class UseClientInjectionPlugin {
|
|
9
|
+
private options;
|
|
10
|
+
private shouldInject;
|
|
11
|
+
constructor(options?: UseClientInjectionPluginOptions);
|
|
3
12
|
apply(compiler: Compiler): void;
|
|
4
13
|
}
|
|
5
14
|
export { UseClientInjectionPlugin };
|
|
@@ -1,21 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UseClientInjectionPlugin = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
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"));
|
|
5
8
|
class UseClientInjectionPlugin {
|
|
9
|
+
options;
|
|
10
|
+
shouldInject = false; // flag determining if injection should occur
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
6
14
|
apply(compiler) {
|
|
7
|
-
//
|
|
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
|
|
8
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
|
+
}
|
|
9
42
|
Object.keys(compilation.assets).forEach((assetName) => {
|
|
10
|
-
console.warn("USE CLIENT INJECTION PLUGIN" + assetName);
|
|
11
43
|
if (assetName.endsWith(".js")) {
|
|
12
44
|
const asset = compilation.assets[assetName];
|
|
13
45
|
let source = asset.source().toString();
|
|
14
|
-
//
|
|
46
|
+
// Only inject if it's not already present
|
|
15
47
|
if (!source.startsWith(`"use client";`) &&
|
|
16
48
|
!source.startsWith(`'use client';`)) {
|
|
17
49
|
source = `"use client";\n${source}`;
|
|
18
|
-
// Use RawSource to create a proper asset source.
|
|
19
50
|
compilation.assets[assetName] = new webpack_sources_1.RawSource(source);
|
|
20
51
|
console.log(`Injected "use client" in: ${assetName}`);
|
|
21
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseClientInjectionPlugin.js","sourceRoot":"","sources":["../../src/plugins/UseClientInjectionPlugin.ts"],"names":[],"mappings":"
|
|
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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