react-code-locator 0.1.15 → 0.1.17

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 (56) hide show
  1. package/README.md +54 -0
  2. package/dist/core/transform-cjs.cjs +7014 -0
  3. package/dist/core/webpackPitchLoader-cjs.cjs +7032 -0
  4. package/dist/esbuild.cjs +7025 -295
  5. package/dist/esbuild.cjs.map +1 -1
  6. package/dist/esbuild.d.cts +38 -6
  7. package/dist/esbuild.d.ts +38 -6
  8. package/dist/esbuild.js +7025 -295
  9. package/dist/esbuild.js.map +1 -1
  10. package/dist/swc.cjs +7020 -293
  11. package/dist/swc.cjs.map +1 -1
  12. package/dist/swc.d.cts +43 -19
  13. package/dist/swc.d.ts +43 -19
  14. package/dist/swc.js +7020 -293
  15. package/dist/swc.js.map +1 -1
  16. package/dist/transform-CXh-m5Ez.d.cts +12 -0
  17. package/dist/transform-CXh-m5Ez.d.ts +12 -0
  18. package/dist/unplugin.cjs +7147 -0
  19. package/dist/unplugin.cjs.map +1 -0
  20. package/dist/unplugin.d.cts +41 -0
  21. package/dist/unplugin.d.ts +41 -0
  22. package/dist/unplugin.js +7118 -0
  23. package/dist/unplugin.js.map +1 -0
  24. package/dist/vite.cjs +7029 -304
  25. package/dist/vite.cjs.map +1 -1
  26. package/dist/vite.d.cts +39 -14
  27. package/dist/vite.d.ts +39 -14
  28. package/dist/vite.js +7029 -303
  29. package/dist/vite.js.map +1 -1
  30. package/dist/webpack.cjs +85 -61
  31. package/dist/webpack.cjs.map +1 -1
  32. package/dist/webpack.d.cts +55 -1
  33. package/dist/webpack.d.ts +55 -1
  34. package/dist/webpack.js +51 -71
  35. package/dist/webpack.js.map +1 -1
  36. package/dist/webpackLoader.cjs +7115 -0
  37. package/dist/webpackLoader.cjs.map +1 -0
  38. package/dist/webpackLoader.d.cts +15 -0
  39. package/dist/webpackLoader.d.ts +15 -0
  40. package/dist/webpackLoader.js +7092 -0
  41. package/dist/webpackLoader.js.map +1 -0
  42. package/package.json +26 -11
  43. package/dist/babel.cjs +0 -370
  44. package/dist/babel.cjs.map +0 -1
  45. package/dist/babel.d.cts +0 -13
  46. package/dist/babel.d.ts +0 -13
  47. package/dist/babel.js +0 -341
  48. package/dist/babel.js.map +0 -1
  49. package/dist/babelInjectComponentSource.cjs +0 -342
  50. package/dist/babelInjectComponentSource.cjs.map +0 -1
  51. package/dist/babelInjectComponentSource.d.cts +0 -15
  52. package/dist/babelInjectComponentSource.d.ts +0 -15
  53. package/dist/babelInjectComponentSource.js +0 -317
  54. package/dist/babelInjectComponentSource.js.map +0 -1
  55. package/dist/sourceAdapter-dPr5CgLi.d.cts +0 -14
  56. package/dist/sourceAdapter-dPr5CgLi.d.ts +0 -14
package/dist/webpack.cjs CHANGED
@@ -1,68 +1,92 @@
1
1
  "use strict";
2
-
3
- // src/webpack.cts
4
- var path = require("path");
5
- function injectEntry(entry, runtimeEntry) {
6
- if (!entry) {
7
- return entry;
8
- }
9
- if (typeof entry === "string") {
10
- return [runtimeEntry, entry];
11
- }
12
- if (Array.isArray(entry)) {
13
- return [runtimeEntry, ...entry];
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
17
  }
15
- return Object.fromEntries(
16
- Object.entries(entry).map(([key, value]) => {
17
- if (Array.isArray(value)) {
18
- return [key, [runtimeEntry, ...value]];
19
- }
20
- return [key, [runtimeEntry, value]];
21
- })
22
- );
23
- }
24
- function patchRules(rules, babelPluginPath) {
25
- if (!rules) {
26
- return;
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/webpack.ts
31
+ var webpack_exports = {};
32
+ __export(webpack_exports, {
33
+ ReactCodeLocatorPlugin: () => ReactCodeLocatorPlugin,
34
+ createReactCodeLocatorPlugin: () => createReactCodeLocatorPlugin,
35
+ default: () => webpack_default,
36
+ webpackPlugin: () => webpackPlugin
37
+ });
38
+ module.exports = __toCommonJS(webpack_exports);
39
+ var DEFAULT_INCLUDE = /\.([jt]sx)$/;
40
+ var DEFAULT_EXCLUDE = /node_modules/;
41
+ var ReactCodeLocatorPlugin = class {
42
+ options;
43
+ constructor(options = {}) {
44
+ this.options = options;
27
45
  }
28
- for (const rule of rules) {
29
- if (rule.oneOf) {
30
- patchRules(rule.oneOf, babelPluginPath);
31
- }
32
- if (rule.loader?.includes("babel-loader")) {
33
- rule.options = {
34
- ...rule.options ?? {},
35
- plugins: [...rule.options?.plugins ?? [], babelPluginPath]
36
- };
37
- }
38
- if (rule.use) {
39
- rule.use = rule.use.map((useEntry) => {
40
- if (!useEntry.loader?.includes("babel-loader")) {
41
- return useEntry;
42
- }
43
- return {
44
- ...useEntry,
45
- options: {
46
- ...useEntry.options ?? {},
47
- plugins: [...useEntry.options?.plugins ?? [], babelPluginPath]
46
+ apply(compiler) {
47
+ const {
48
+ include = DEFAULT_INCLUDE,
49
+ exclude = DEFAULT_EXCLUDE,
50
+ projectRoot = process.cwd(),
51
+ injectComponentSource = true,
52
+ injectJsxSource = true
53
+ } = this.options;
54
+ const pluginName = "ReactCodeLocatorPlugin";
55
+ compiler.hooks.afterEnvironment.tap(pluginName, () => {
56
+ const rules = compiler.options.module?.rules || [];
57
+ const loaderPath = require.resolve("./core/webpackPitchLoader-cjs.cjs");
58
+ const rule = {
59
+ test: include,
60
+ exclude,
61
+ enforce: "pre",
62
+ use: [
63
+ {
64
+ loader: loaderPath,
65
+ options: {
66
+ projectRoot,
67
+ injectComponentSource,
68
+ injectJsxSource
69
+ }
48
70
  }
49
- };
50
- });
51
- }
52
- }
53
- }
54
- function withReactComponentJump(config, options = {}) {
55
- const { env = process.env.NODE_ENV ?? "development" } = options;
56
- if (env !== "development") {
57
- return config;
71
+ ]
72
+ };
73
+ rules.unshift(rule);
74
+ if (!compiler.options.module) {
75
+ compiler.options.module = { rules: [] };
76
+ }
77
+ compiler.options.module.rules = rules;
78
+ });
58
79
  }
59
- const babelPluginPath = path.join(__dirname, "babelInjectComponentSource.cjs");
60
- const runtimeEntry = path.join(__dirname, "webpackRuntimeEntry.cjs");
61
- patchRules(config.module?.rules, babelPluginPath);
62
- config.entry = injectEntry(config.entry, runtimeEntry);
63
- return config;
64
- }
65
- module.exports = {
66
- withReactComponentJump
67
80
  };
81
+ function createReactCodeLocatorPlugin(options = {}) {
82
+ return new ReactCodeLocatorPlugin(options);
83
+ }
84
+ var webpack_default = ReactCodeLocatorPlugin;
85
+ var webpackPlugin = createReactCodeLocatorPlugin;
86
+ // Annotate the CommonJS export names for ESM import in node:
87
+ 0 && (module.exports = {
88
+ ReactCodeLocatorPlugin,
89
+ createReactCodeLocatorPlugin,
90
+ webpackPlugin
91
+ });
68
92
  //# sourceMappingURL=webpack.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/webpack.cts"],"sourcesContent":["const path = require(\"node:path\");\n\ntype WebpackAdapterOptions = {\n env?: \"development\" | \"production\" | string;\n};\n\ntype Rule = {\n oneOf?: Rule[];\n use?: Array<{ loader?: string; options?: { plugins?: unknown[] } }>;\n loader?: string;\n options?: { plugins?: unknown[] };\n};\n\ntype WebpackConfig = {\n entry?: string | string[] | Record<string, string | string[]>;\n module?: {\n rules?: Rule[];\n };\n};\n\nfunction injectEntry(entry: WebpackConfig[\"entry\"], runtimeEntry: string) {\n if (!entry) {\n return entry;\n }\n\n if (typeof entry === \"string\") {\n return [runtimeEntry, entry];\n }\n\n if (Array.isArray(entry)) {\n return [runtimeEntry, ...entry];\n }\n\n return Object.fromEntries(\n Object.entries(entry).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [key, [runtimeEntry, ...value]];\n }\n\n return [key, [runtimeEntry, value]];\n }),\n );\n}\n\nfunction patchRules(rules: Rule[] | undefined, babelPluginPath: string) {\n if (!rules) {\n return;\n }\n\n for (const rule of rules) {\n if (rule.oneOf) {\n patchRules(rule.oneOf, babelPluginPath);\n }\n\n if (rule.loader?.includes(\"babel-loader\")) {\n rule.options = {\n ...(rule.options ?? {}),\n plugins: [...(rule.options?.plugins ?? []), babelPluginPath],\n };\n }\n\n if (rule.use) {\n rule.use = rule.use.map((useEntry) => {\n if (!useEntry.loader?.includes(\"babel-loader\")) {\n return useEntry;\n }\n\n return {\n ...useEntry,\n options: {\n ...(useEntry.options ?? {}),\n plugins: [...(useEntry.options?.plugins ?? []), babelPluginPath],\n },\n };\n });\n }\n }\n}\n\nfunction withReactComponentJump(config: WebpackConfig, options: WebpackAdapterOptions = {}) {\n const { env = process.env.NODE_ENV ?? \"development\" } = options;\n if (env !== \"development\") {\n return config;\n }\n\n const babelPluginPath = path.join(__dirname, \"babelInjectComponentSource.cjs\");\n const runtimeEntry = path.join(__dirname, \"webpackRuntimeEntry.cjs\");\n\n patchRules(config.module?.rules, babelPluginPath);\n config.entry = injectEntry(config.entry, runtimeEntry);\n return config;\n}\n\nmodule.exports = {\n withReactComponentJump,\n};\n"],"mappings":";;;AAAA,IAAM,OAAO,QAAQ,MAAW;AAoBhC,SAAS,YAAY,OAA+B,cAAsB;AACxE,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,CAAC,cAAc,KAAK;AAAA,EAC7B;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,CAAC,cAAc,GAAG,KAAK;AAAA,EAChC;AAEA,SAAO,OAAO;AAAA,IACZ,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAC1C,UAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAO,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC;AAAA,MACvC;AAEA,aAAO,CAAC,KAAK,CAAC,cAAc,KAAK,CAAC;AAAA,IACpC,CAAC;AAAA,EACH;AACF;AAEA,SAAS,WAAW,OAA2B,iBAAyB;AACtE,MAAI,CAAC,OAAO;AACV;AAAA,EACF;AAEA,aAAW,QAAQ,OAAO;AACxB,QAAI,KAAK,OAAO;AACd,iBAAW,KAAK,OAAO,eAAe;AAAA,IACxC;AAEA,QAAI,KAAK,QAAQ,SAAS,cAAc,GAAG;AACzC,WAAK,UAAU;AAAA,QACb,GAAI,KAAK,WAAW,CAAC;AAAA,QACrB,SAAS,CAAC,GAAI,KAAK,SAAS,WAAW,CAAC,GAAI,eAAe;AAAA,MAC7D;AAAA,IACF;AAEA,QAAI,KAAK,KAAK;AACZ,WAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa;AACpC,YAAI,CAAC,SAAS,QAAQ,SAAS,cAAc,GAAG;AAC9C,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,UACL,GAAG;AAAA,UACH,SAAS;AAAA,YACP,GAAI,SAAS,WAAW,CAAC;AAAA,YACzB,SAAS,CAAC,GAAI,SAAS,SAAS,WAAW,CAAC,GAAI,eAAe;AAAA,UACjE;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,uBAAuB,QAAuB,UAAiC,CAAC,GAAG;AAC1F,QAAM,EAAE,MAAM,QAAQ,IAAI,YAAY,cAAc,IAAI;AACxD,MAAI,QAAQ,eAAe;AACzB,WAAO;AAAA,EACT;AAEA,QAAM,kBAAkB,KAAK,KAAK,WAAW,gCAAgC;AAC7E,QAAM,eAAe,KAAK,KAAK,WAAW,yBAAyB;AAEnE,aAAW,OAAO,QAAQ,OAAO,eAAe;AAChD,SAAO,QAAQ,YAAY,OAAO,OAAO,YAAY;AACrD,SAAO;AACT;AAEA,OAAO,UAAU;AAAA,EACf;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/webpack.ts"],"sourcesContent":["/**\n * Webpack Plugin for react-code-locator\n * CJS-compatible version - no unplugin dependency\n * \n * Usage:\n * ```js\n * // webpack.config.js\n * const { ReactCodeLocatorPlugin } = require('react-code-locator/webpack');\n * \n * module.exports = {\n * plugins: [\n * new ReactCodeLocatorPlugin()\n * ]\n * };\n * ```\n */\n\nimport { transformSource } from \"./core/transform\";\nimport type { Compiler, NormalModule } from \"webpack\";\n\nexport interface ReactCodeLocatorWebpackOptions {\n /** \n * Enable source transform for component definitions\n * @default true\n */\n injectComponentSource?: boolean;\n \n /** \n * Enable source transform for JSX call sites\n * @default true\n */\n injectJsxSource?: boolean;\n \n /**\n * Project root for relative path calculation\n * @default process.cwd()\n */\n projectRoot?: string;\n \n /**\n * Include filter for file paths\n * @default /\\.[jt]sx$/\n */\n include?: RegExp | RegExp[];\n \n /**\n * Exclude filter for file paths\n * @default /node_modules/\n */\n exclude?: RegExp | RegExp[];\n}\n\nconst DEFAULT_INCLUDE = /\\.([jt]sx)$/;\nconst DEFAULT_EXCLUDE = /node_modules/;\n\nfunction shouldTransform(id: string, include: RegExp | RegExp[], exclude: RegExp | RegExp[]): boolean {\n const includePatterns = Array.isArray(include) ? include : [include];\n const excludePatterns = Array.isArray(exclude) ? exclude : [exclude];\n \n if (excludePatterns.some(pattern => pattern.test(id))) {\n return false;\n }\n \n return includePatterns.some(pattern => pattern.test(id));\n}\n\nexport class ReactCodeLocatorPlugin {\n private options: ReactCodeLocatorWebpackOptions;\n\n constructor(options: ReactCodeLocatorWebpackOptions = {}) {\n this.options = options;\n }\n\n apply(compiler: Compiler): void {\n const {\n include = DEFAULT_INCLUDE,\n exclude = DEFAULT_EXCLUDE,\n projectRoot = process.cwd(),\n injectComponentSource = true,\n injectJsxSource = true,\n } = this.options;\n\n const pluginName = \"ReactCodeLocatorPlugin\";\n\n // Add loader rule using compiler.options.module.rules\n compiler.hooks.afterEnvironment.tap(pluginName, () => {\n const rules = compiler.options.module?.rules || [];\n \n // Create loader path - use bundled CJS version (relative to webpack.cjs)\n const loaderPath = require.resolve('./core/webpackPitchLoader-cjs.cjs');\n \n // Create rule\n const rule = {\n test: include,\n exclude: exclude,\n enforce: 'pre' as const,\n use: [\n {\n loader: loaderPath,\n options: {\n projectRoot,\n injectComponentSource,\n injectJsxSource,\n },\n },\n ],\n };\n \n // Add rule to beginning\n rules.unshift(rule);\n \n if (!compiler.options.module) {\n compiler.options.module = { rules: [] } as any;\n }\n compiler.options.module.rules = rules;\n });\n }\n}\n\n// Factory function\nexport function createReactCodeLocatorPlugin(options: ReactCodeLocatorWebpackOptions = {}): ReactCodeLocatorPlugin {\n return new ReactCodeLocatorPlugin(options);\n}\n\n// Default export\nexport default ReactCodeLocatorPlugin;\n\n// Also export as webpackPlugin for compatibility\nexport const webpackPlugin = createReactCodeLocatorPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDA,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AAajB,IAAM,yBAAN,MAA6B;AAAA,EAC1B;AAAA,EAER,YAAY,UAA0C,CAAC,GAAG;AACxD,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,UAA0B;AAC9B,UAAM;AAAA,MACJ,UAAU;AAAA,MACV,UAAU;AAAA,MACV,cAAc,QAAQ,IAAI;AAAA,MAC1B,wBAAwB;AAAA,MACxB,kBAAkB;AAAA,IACpB,IAAI,KAAK;AAET,UAAM,aAAa;AAGnB,aAAS,MAAM,iBAAiB,IAAI,YAAY,MAAM;AACpD,YAAM,QAAQ,SAAS,QAAQ,QAAQ,SAAS,CAAC;AAGjD,YAAM,aAAa,gBAAgB,mCAAmC;AAGtE,YAAM,OAAO;AAAA,QACX,MAAM;AAAA,QACN;AAAA,QACA,SAAS;AAAA,QACT,KAAK;AAAA,UACH;AAAA,YACE,QAAQ;AAAA,YACR,SAAS;AAAA,cACP;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAGA,YAAM,QAAQ,IAAI;AAElB,UAAI,CAAC,SAAS,QAAQ,QAAQ;AAC5B,iBAAS,QAAQ,SAAS,EAAE,OAAO,CAAC,EAAE;AAAA,MACxC;AACA,eAAS,QAAQ,OAAO,QAAQ;AAAA,IAClC,CAAC;AAAA,EACH;AACF;AAGO,SAAS,6BAA6B,UAA0C,CAAC,GAA2B;AACjH,SAAO,IAAI,uBAAuB,OAAO;AAC3C;AAGA,IAAO,kBAAQ;AAGR,IAAM,gBAAgB;","names":[]}
@@ -1,2 +1,56 @@
1
+ import { Compiler } from 'webpack';
1
2
 
2
- export { }
3
+ /**
4
+ * Webpack Plugin for react-code-locator
5
+ * CJS-compatible version - no unplugin dependency
6
+ *
7
+ * Usage:
8
+ * ```js
9
+ * // webpack.config.js
10
+ * const { ReactCodeLocatorPlugin } = require('react-code-locator/webpack');
11
+ *
12
+ * module.exports = {
13
+ * plugins: [
14
+ * new ReactCodeLocatorPlugin()
15
+ * ]
16
+ * };
17
+ * ```
18
+ */
19
+
20
+ interface ReactCodeLocatorWebpackOptions {
21
+ /**
22
+ * Enable source transform for component definitions
23
+ * @default true
24
+ */
25
+ injectComponentSource?: boolean;
26
+ /**
27
+ * Enable source transform for JSX call sites
28
+ * @default true
29
+ */
30
+ injectJsxSource?: boolean;
31
+ /**
32
+ * Project root for relative path calculation
33
+ * @default process.cwd()
34
+ */
35
+ projectRoot?: string;
36
+ /**
37
+ * Include filter for file paths
38
+ * @default /\.[jt]sx$/
39
+ */
40
+ include?: RegExp | RegExp[];
41
+ /**
42
+ * Exclude filter for file paths
43
+ * @default /node_modules/
44
+ */
45
+ exclude?: RegExp | RegExp[];
46
+ }
47
+ declare class ReactCodeLocatorPlugin {
48
+ private options;
49
+ constructor(options?: ReactCodeLocatorWebpackOptions);
50
+ apply(compiler: Compiler): void;
51
+ }
52
+ declare function createReactCodeLocatorPlugin(options?: ReactCodeLocatorWebpackOptions): ReactCodeLocatorPlugin;
53
+
54
+ declare const webpackPlugin: typeof createReactCodeLocatorPlugin;
55
+
56
+ export { ReactCodeLocatorPlugin, type ReactCodeLocatorWebpackOptions, createReactCodeLocatorPlugin, ReactCodeLocatorPlugin as default, webpackPlugin };
package/dist/webpack.d.ts CHANGED
@@ -1,2 +1,56 @@
1
+ import { Compiler } from 'webpack';
1
2
 
2
- export { }
3
+ /**
4
+ * Webpack Plugin for react-code-locator
5
+ * CJS-compatible version - no unplugin dependency
6
+ *
7
+ * Usage:
8
+ * ```js
9
+ * // webpack.config.js
10
+ * const { ReactCodeLocatorPlugin } = require('react-code-locator/webpack');
11
+ *
12
+ * module.exports = {
13
+ * plugins: [
14
+ * new ReactCodeLocatorPlugin()
15
+ * ]
16
+ * };
17
+ * ```
18
+ */
19
+
20
+ interface ReactCodeLocatorWebpackOptions {
21
+ /**
22
+ * Enable source transform for component definitions
23
+ * @default true
24
+ */
25
+ injectComponentSource?: boolean;
26
+ /**
27
+ * Enable source transform for JSX call sites
28
+ * @default true
29
+ */
30
+ injectJsxSource?: boolean;
31
+ /**
32
+ * Project root for relative path calculation
33
+ * @default process.cwd()
34
+ */
35
+ projectRoot?: string;
36
+ /**
37
+ * Include filter for file paths
38
+ * @default /\.[jt]sx$/
39
+ */
40
+ include?: RegExp | RegExp[];
41
+ /**
42
+ * Exclude filter for file paths
43
+ * @default /node_modules/
44
+ */
45
+ exclude?: RegExp | RegExp[];
46
+ }
47
+ declare class ReactCodeLocatorPlugin {
48
+ private options;
49
+ constructor(options?: ReactCodeLocatorWebpackOptions);
50
+ apply(compiler: Compiler): void;
51
+ }
52
+ declare function createReactCodeLocatorPlugin(options?: ReactCodeLocatorWebpackOptions): ReactCodeLocatorPlugin;
53
+
54
+ declare const webpackPlugin: typeof createReactCodeLocatorPlugin;
55
+
56
+ export { ReactCodeLocatorPlugin, type ReactCodeLocatorWebpackOptions, createReactCodeLocatorPlugin, ReactCodeLocatorPlugin as default, webpackPlugin };
package/dist/webpack.js CHANGED
@@ -1,82 +1,62 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
1
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
2
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
3
  }) : x)(function(x) {
5
4
  if (typeof require !== "undefined") return require.apply(this, arguments);
6
5
  throw Error('Dynamic require of "' + x + '" is not supported');
7
6
  });
8
- var __commonJS = (cb, mod) => function __require2() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
7
 
12
- // src/webpack.cts
13
- var require_webpack = __commonJS({
14
- "src/webpack.cts"(exports, module) {
15
- var path = __require("path");
16
- function injectEntry(entry, runtimeEntry) {
17
- if (!entry) {
18
- return entry;
19
- }
20
- if (typeof entry === "string") {
21
- return [runtimeEntry, entry];
22
- }
23
- if (Array.isArray(entry)) {
24
- return [runtimeEntry, ...entry];
25
- }
26
- return Object.fromEntries(
27
- Object.entries(entry).map(([key, value]) => {
28
- if (Array.isArray(value)) {
29
- return [key, [runtimeEntry, ...value]];
30
- }
31
- return [key, [runtimeEntry, value]];
32
- })
33
- );
34
- }
35
- function patchRules(rules, babelPluginPath) {
36
- if (!rules) {
37
- return;
38
- }
39
- for (const rule of rules) {
40
- if (rule.oneOf) {
41
- patchRules(rule.oneOf, babelPluginPath);
42
- }
43
- if (rule.loader?.includes("babel-loader")) {
44
- rule.options = {
45
- ...rule.options ?? {},
46
- plugins: [...rule.options?.plugins ?? [], babelPluginPath]
47
- };
48
- }
49
- if (rule.use) {
50
- rule.use = rule.use.map((useEntry) => {
51
- if (!useEntry.loader?.includes("babel-loader")) {
52
- return useEntry;
8
+ // src/webpack.ts
9
+ var DEFAULT_INCLUDE = /\.([jt]sx)$/;
10
+ var DEFAULT_EXCLUDE = /node_modules/;
11
+ var ReactCodeLocatorPlugin = class {
12
+ options;
13
+ constructor(options = {}) {
14
+ this.options = options;
15
+ }
16
+ apply(compiler) {
17
+ const {
18
+ include = DEFAULT_INCLUDE,
19
+ exclude = DEFAULT_EXCLUDE,
20
+ projectRoot = process.cwd(),
21
+ injectComponentSource = true,
22
+ injectJsxSource = true
23
+ } = this.options;
24
+ const pluginName = "ReactCodeLocatorPlugin";
25
+ compiler.hooks.afterEnvironment.tap(pluginName, () => {
26
+ const rules = compiler.options.module?.rules || [];
27
+ const loaderPath = __require.resolve("./core/webpackPitchLoader-cjs.cjs");
28
+ const rule = {
29
+ test: include,
30
+ exclude,
31
+ enforce: "pre",
32
+ use: [
33
+ {
34
+ loader: loaderPath,
35
+ options: {
36
+ projectRoot,
37
+ injectComponentSource,
38
+ injectJsxSource
53
39
  }
54
- return {
55
- ...useEntry,
56
- options: {
57
- ...useEntry.options ?? {},
58
- plugins: [...useEntry.options?.plugins ?? [], babelPluginPath]
59
- }
60
- };
61
- });
62
- }
63
- }
64
- }
65
- function withReactComponentJump(config, options = {}) {
66
- const { env = process.env.NODE_ENV ?? "development" } = options;
67
- if (env !== "development") {
68
- return config;
40
+ }
41
+ ]
42
+ };
43
+ rules.unshift(rule);
44
+ if (!compiler.options.module) {
45
+ compiler.options.module = { rules: [] };
69
46
  }
70
- const babelPluginPath = path.join(__dirname, "babelInjectComponentSource.cjs");
71
- const runtimeEntry = path.join(__dirname, "webpackRuntimeEntry.cjs");
72
- patchRules(config.module?.rules, babelPluginPath);
73
- config.entry = injectEntry(config.entry, runtimeEntry);
74
- return config;
75
- }
76
- module.exports = {
77
- withReactComponentJump
78
- };
47
+ compiler.options.module.rules = rules;
48
+ });
79
49
  }
80
- });
81
- export default require_webpack();
50
+ };
51
+ function createReactCodeLocatorPlugin(options = {}) {
52
+ return new ReactCodeLocatorPlugin(options);
53
+ }
54
+ var webpack_default = ReactCodeLocatorPlugin;
55
+ var webpackPlugin = createReactCodeLocatorPlugin;
56
+ export {
57
+ ReactCodeLocatorPlugin,
58
+ createReactCodeLocatorPlugin,
59
+ webpack_default as default,
60
+ webpackPlugin
61
+ };
82
62
  //# sourceMappingURL=webpack.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/webpack.cts"],"sourcesContent":["const path = require(\"node:path\");\n\ntype WebpackAdapterOptions = {\n env?: \"development\" | \"production\" | string;\n};\n\ntype Rule = {\n oneOf?: Rule[];\n use?: Array<{ loader?: string; options?: { plugins?: unknown[] } }>;\n loader?: string;\n options?: { plugins?: unknown[] };\n};\n\ntype WebpackConfig = {\n entry?: string | string[] | Record<string, string | string[]>;\n module?: {\n rules?: Rule[];\n };\n};\n\nfunction injectEntry(entry: WebpackConfig[\"entry\"], runtimeEntry: string) {\n if (!entry) {\n return entry;\n }\n\n if (typeof entry === \"string\") {\n return [runtimeEntry, entry];\n }\n\n if (Array.isArray(entry)) {\n return [runtimeEntry, ...entry];\n }\n\n return Object.fromEntries(\n Object.entries(entry).map(([key, value]) => {\n if (Array.isArray(value)) {\n return [key, [runtimeEntry, ...value]];\n }\n\n return [key, [runtimeEntry, value]];\n }),\n );\n}\n\nfunction patchRules(rules: Rule[] | undefined, babelPluginPath: string) {\n if (!rules) {\n return;\n }\n\n for (const rule of rules) {\n if (rule.oneOf) {\n patchRules(rule.oneOf, babelPluginPath);\n }\n\n if (rule.loader?.includes(\"babel-loader\")) {\n rule.options = {\n ...(rule.options ?? {}),\n plugins: [...(rule.options?.plugins ?? []), babelPluginPath],\n };\n }\n\n if (rule.use) {\n rule.use = rule.use.map((useEntry) => {\n if (!useEntry.loader?.includes(\"babel-loader\")) {\n return useEntry;\n }\n\n return {\n ...useEntry,\n options: {\n ...(useEntry.options ?? {}),\n plugins: [...(useEntry.options?.plugins ?? []), babelPluginPath],\n },\n };\n });\n }\n }\n}\n\nfunction withReactComponentJump(config: WebpackConfig, options: WebpackAdapterOptions = {}) {\n const { env = process.env.NODE_ENV ?? \"development\" } = options;\n if (env !== \"development\") {\n return config;\n }\n\n const babelPluginPath = path.join(__dirname, \"babelInjectComponentSource.cjs\");\n const runtimeEntry = path.join(__dirname, \"webpackRuntimeEntry.cjs\");\n\n patchRules(config.module?.rules, babelPluginPath);\n config.entry = injectEntry(config.entry, runtimeEntry);\n return config;\n}\n\nmodule.exports = {\n withReactComponentJump,\n};\n"],"mappings":";;;;;;;;;;;;AAAA;AAAA;AAAA,QAAM,OAAO,UAAQ,MAAW;AAoBhC,aAAS,YAAY,OAA+B,cAAsB;AACxE,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AAEA,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO,CAAC,cAAc,KAAK;AAAA,MAC7B;AAEA,UAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,eAAO,CAAC,cAAc,GAAG,KAAK;AAAA,MAChC;AAEA,aAAO,OAAO;AAAA,QACZ,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AAC1C,cAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,mBAAO,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,CAAC;AAAA,UACvC;AAEA,iBAAO,CAAC,KAAK,CAAC,cAAc,KAAK,CAAC;AAAA,QACpC,CAAC;AAAA,MACH;AAAA,IACF;AAEA,aAAS,WAAW,OAA2B,iBAAyB;AACtE,UAAI,CAAC,OAAO;AACV;AAAA,MACF;AAEA,iBAAW,QAAQ,OAAO;AACxB,YAAI,KAAK,OAAO;AACd,qBAAW,KAAK,OAAO,eAAe;AAAA,QACxC;AAEA,YAAI,KAAK,QAAQ,SAAS,cAAc,GAAG;AACzC,eAAK,UAAU;AAAA,YACb,GAAI,KAAK,WAAW,CAAC;AAAA,YACrB,SAAS,CAAC,GAAI,KAAK,SAAS,WAAW,CAAC,GAAI,eAAe;AAAA,UAC7D;AAAA,QACF;AAEA,YAAI,KAAK,KAAK;AACZ,eAAK,MAAM,KAAK,IAAI,IAAI,CAAC,aAAa;AACpC,gBAAI,CAAC,SAAS,QAAQ,SAAS,cAAc,GAAG;AAC9C,qBAAO;AAAA,YACT;AAEA,mBAAO;AAAA,cACL,GAAG;AAAA,cACH,SAAS;AAAA,gBACP,GAAI,SAAS,WAAW,CAAC;AAAA,gBACzB,SAAS,CAAC,GAAI,SAAS,SAAS,WAAW,CAAC,GAAI,eAAe;AAAA,cACjE;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAEA,aAAS,uBAAuB,QAAuB,UAAiC,CAAC,GAAG;AAC1F,YAAM,EAAE,MAAM,QAAQ,IAAI,YAAY,cAAc,IAAI;AACxD,UAAI,QAAQ,eAAe;AACzB,eAAO;AAAA,MACT;AAEA,YAAM,kBAAkB,KAAK,KAAK,WAAW,gCAAgC;AAC7E,YAAM,eAAe,KAAK,KAAK,WAAW,yBAAyB;AAEnE,iBAAW,OAAO,QAAQ,OAAO,eAAe;AAChD,aAAO,QAAQ,YAAY,OAAO,OAAO,YAAY;AACrD,aAAO;AAAA,IACT;AAEA,WAAO,UAAU;AAAA,MACf;AAAA,IACF;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../src/webpack.ts"],"sourcesContent":["/**\n * Webpack Plugin for react-code-locator\n * CJS-compatible version - no unplugin dependency\n * \n * Usage:\n * ```js\n * // webpack.config.js\n * const { ReactCodeLocatorPlugin } = require('react-code-locator/webpack');\n * \n * module.exports = {\n * plugins: [\n * new ReactCodeLocatorPlugin()\n * ]\n * };\n * ```\n */\n\nimport { transformSource } from \"./core/transform\";\nimport type { Compiler, NormalModule } from \"webpack\";\n\nexport interface ReactCodeLocatorWebpackOptions {\n /** \n * Enable source transform for component definitions\n * @default true\n */\n injectComponentSource?: boolean;\n \n /** \n * Enable source transform for JSX call sites\n * @default true\n */\n injectJsxSource?: boolean;\n \n /**\n * Project root for relative path calculation\n * @default process.cwd()\n */\n projectRoot?: string;\n \n /**\n * Include filter for file paths\n * @default /\\.[jt]sx$/\n */\n include?: RegExp | RegExp[];\n \n /**\n * Exclude filter for file paths\n * @default /node_modules/\n */\n exclude?: RegExp | RegExp[];\n}\n\nconst DEFAULT_INCLUDE = /\\.([jt]sx)$/;\nconst DEFAULT_EXCLUDE = /node_modules/;\n\nfunction shouldTransform(id: string, include: RegExp | RegExp[], exclude: RegExp | RegExp[]): boolean {\n const includePatterns = Array.isArray(include) ? include : [include];\n const excludePatterns = Array.isArray(exclude) ? exclude : [exclude];\n \n if (excludePatterns.some(pattern => pattern.test(id))) {\n return false;\n }\n \n return includePatterns.some(pattern => pattern.test(id));\n}\n\nexport class ReactCodeLocatorPlugin {\n private options: ReactCodeLocatorWebpackOptions;\n\n constructor(options: ReactCodeLocatorWebpackOptions = {}) {\n this.options = options;\n }\n\n apply(compiler: Compiler): void {\n const {\n include = DEFAULT_INCLUDE,\n exclude = DEFAULT_EXCLUDE,\n projectRoot = process.cwd(),\n injectComponentSource = true,\n injectJsxSource = true,\n } = this.options;\n\n const pluginName = \"ReactCodeLocatorPlugin\";\n\n // Add loader rule using compiler.options.module.rules\n compiler.hooks.afterEnvironment.tap(pluginName, () => {\n const rules = compiler.options.module?.rules || [];\n \n // Create loader path - use bundled CJS version (relative to webpack.cjs)\n const loaderPath = require.resolve('./core/webpackPitchLoader-cjs.cjs');\n \n // Create rule\n const rule = {\n test: include,\n exclude: exclude,\n enforce: 'pre' as const,\n use: [\n {\n loader: loaderPath,\n options: {\n projectRoot,\n injectComponentSource,\n injectJsxSource,\n },\n },\n ],\n };\n \n // Add rule to beginning\n rules.unshift(rule);\n \n if (!compiler.options.module) {\n compiler.options.module = { rules: [] } as any;\n }\n compiler.options.module.rules = rules;\n });\n }\n}\n\n// Factory function\nexport function createReactCodeLocatorPlugin(options: ReactCodeLocatorWebpackOptions = {}): ReactCodeLocatorPlugin {\n return new ReactCodeLocatorPlugin(options);\n}\n\n// Default export\nexport default ReactCodeLocatorPlugin;\n\n// Also export as webpackPlugin for compatibility\nexport const webpackPlugin = createReactCodeLocatorPlugin;\n"],"mappings":";;;;;;;;AAoDA,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AAajB,IAAM,yBAAN,MAA6B;AAAA,EAC1B;AAAA,EAER,YAAY,UAA0C,CAAC,GAAG;AACxD,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,MAAM,UAA0B;AAC9B,UAAM;AAAA,MACJ,UAAU;AAAA,MACV,UAAU;AAAA,MACV,cAAc,QAAQ,IAAI;AAAA,MAC1B,wBAAwB;AAAA,MACxB,kBAAkB;AAAA,IACpB,IAAI,KAAK;AAET,UAAM,aAAa;AAGnB,aAAS,MAAM,iBAAiB,IAAI,YAAY,MAAM;AACpD,YAAM,QAAQ,SAAS,QAAQ,QAAQ,SAAS,CAAC;AAGjD,YAAM,aAAa,UAAQ,QAAQ,mCAAmC;AAGtE,YAAM,OAAO;AAAA,QACX,MAAM;AAAA,QACN;AAAA,QACA,SAAS;AAAA,QACT,KAAK;AAAA,UACH;AAAA,YACE,QAAQ;AAAA,YACR,SAAS;AAAA,cACP;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAGA,YAAM,QAAQ,IAAI;AAElB,UAAI,CAAC,SAAS,QAAQ,QAAQ;AAC5B,iBAAS,QAAQ,SAAS,EAAE,OAAO,CAAC,EAAE;AAAA,MACxC;AACA,eAAS,QAAQ,OAAO,QAAQ;AAAA,IAClC,CAAC;AAAA,EACH;AACF;AAGO,SAAS,6BAA6B,UAA0C,CAAC,GAA2B;AACjH,SAAO,IAAI,uBAAuB,OAAO;AAC3C;AAGA,IAAO,kBAAQ;AAGR,IAAM,gBAAgB;","names":[]}