@datadog/esbuild-plugin 2.3.1 → 2.3.3-dev-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/rspack/loaders/load.ts
@@ -35,11 +25,25 @@ __export(load_exports, {
35
25
  module.exports = __toCommonJS(load_exports);
36
26
 
37
27
  // src/rspack/context.ts
28
+ var import_path = require("path");
38
29
  var import_buffer = require("buffer");
39
- var import_webpack_sources = __toESM(require("webpack-sources"));
40
30
  var import_acorn = require("acorn");
41
- function createBuildContext(compilation) {
31
+ function createBuildContext(compiler, compilation, loaderContext) {
42
32
  return {
33
+ getNativeBuildContext() {
34
+ return {
35
+ framework: "rspack",
36
+ compiler,
37
+ compilation,
38
+ loaderContext
39
+ };
40
+ },
41
+ addWatchFile(file) {
42
+ compilation.fileDependencies.add((0, import_path.resolve)(process.cwd(), file));
43
+ },
44
+ getWatchFiles() {
45
+ return Array.from(compilation.fileDependencies);
46
+ },
43
47
  parse(code, opts = {}) {
44
48
  return import_acorn.Parser.parse(code, {
45
49
  sourceType: "module",
@@ -48,22 +52,17 @@ function createBuildContext(compilation) {
48
52
  ...opts
49
53
  });
50
54
  },
51
- addWatchFile() {
52
- },
53
55
  emitFile(emittedFile) {
54
56
  const outFileName = emittedFile.fileName || emittedFile.name;
55
57
  if (emittedFile.source && outFileName) {
58
+ const { sources } = compilation.compiler.webpack;
56
59
  compilation.emitAsset(
57
60
  outFileName,
58
- new import_webpack_sources.default.RawSource(
59
- // @ts-expect-error types mismatch
61
+ new sources.RawSource(
60
62
  typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
61
63
  )
62
64
  );
63
65
  }
64
- },
65
- getWatchFiles() {
66
- return [];
67
66
  }
68
67
  };
69
68
  }
@@ -83,30 +82,39 @@ function normalizeMessage(error) {
83
82
  }
84
83
 
85
84
  // src/utils.ts
86
- var import_path = require("path");
85
+ var import_path2 = require("path");
87
86
  function normalizeAbsolutePath(path) {
88
- if ((0, import_path.isAbsolute)(path))
89
- return (0, import_path.normalize)(path);
87
+ if ((0, import_path2.isAbsolute)(path))
88
+ return (0, import_path2.normalize)(path);
90
89
  else
91
90
  return path;
92
91
  }
93
92
 
93
+ // src/rspack/utils.ts
94
+ var import_path3 = require("path");
95
+ function decodeVirtualModuleId(encoded, _plugin) {
96
+ return decodeURIComponent((0, import_path3.basename)(encoded));
97
+ }
98
+ function isVirtualModuleId(encoded, plugin) {
99
+ return (0, import_path3.dirname)(encoded) === plugin.__virtualModulePrefix;
100
+ }
101
+
94
102
  // src/rspack/loaders/load.ts
95
103
  async function load(source, map) {
96
104
  var _a;
97
105
  const callback = this.async();
98
106
  const { unpluginName } = this.query;
99
107
  const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
100
- const id = this.resource;
108
+ let id = this.resource;
101
109
  if (!(plugin == null ? void 0 : plugin.load) || !id)
102
110
  return callback(null, source, map);
103
- if (plugin.loadInclude && !plugin.loadInclude(id))
104
- return callback(null, source, map);
111
+ if (isVirtualModuleId(id, plugin))
112
+ id = decodeVirtualModuleId(id, plugin);
105
113
  const context = createContext(this);
106
114
  const res = await plugin.load.call(
107
115
  Object.assign(
108
116
  {},
109
- this._compilation && createBuildContext(this._compilation),
117
+ this._compilation && createBuildContext(this._compiler, this._compilation, this),
110
118
  context
111
119
  ),
112
120
  normalizeAbsolutePath(id)
@@ -1,9 +1,23 @@
1
1
  // src/rspack/context.ts
2
+ import { resolve } from "path";
2
3
  import { Buffer } from "buffer";
3
- import sources from "webpack-sources";
4
4
  import { Parser } from "acorn";
5
- function createBuildContext(compilation) {
5
+ function createBuildContext(compiler, compilation, loaderContext) {
6
6
  return {
7
+ getNativeBuildContext() {
8
+ return {
9
+ framework: "rspack",
10
+ compiler,
11
+ compilation,
12
+ loaderContext
13
+ };
14
+ },
15
+ addWatchFile(file) {
16
+ compilation.fileDependencies.add(resolve(process.cwd(), file));
17
+ },
18
+ getWatchFiles() {
19
+ return Array.from(compilation.fileDependencies);
20
+ },
7
21
  parse(code, opts = {}) {
8
22
  return Parser.parse(code, {
9
23
  sourceType: "module",
@@ -12,22 +26,17 @@ function createBuildContext(compilation) {
12
26
  ...opts
13
27
  });
14
28
  },
15
- addWatchFile() {
16
- },
17
29
  emitFile(emittedFile) {
18
30
  const outFileName = emittedFile.fileName || emittedFile.name;
19
31
  if (emittedFile.source && outFileName) {
32
+ const { sources } = compilation.compiler.webpack;
20
33
  compilation.emitAsset(
21
34
  outFileName,
22
35
  new sources.RawSource(
23
- // @ts-expect-error types mismatch
24
36
  typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
25
37
  )
26
38
  );
27
39
  }
28
- },
29
- getWatchFiles() {
30
- return [];
31
40
  }
32
41
  };
33
42
  }
@@ -55,22 +64,31 @@ function normalizeAbsolutePath(path) {
55
64
  return path;
56
65
  }
57
66
 
67
+ // src/rspack/utils.ts
68
+ import { basename, dirname, resolve as resolve2 } from "path";
69
+ function decodeVirtualModuleId(encoded, _plugin) {
70
+ return decodeURIComponent(basename(encoded));
71
+ }
72
+ function isVirtualModuleId(encoded, plugin) {
73
+ return dirname(encoded) === plugin.__virtualModulePrefix;
74
+ }
75
+
58
76
  // src/rspack/loaders/load.ts
59
77
  async function load(source, map) {
60
78
  var _a;
61
79
  const callback = this.async();
62
80
  const { unpluginName } = this.query;
63
81
  const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
64
- const id = this.resource;
82
+ let id = this.resource;
65
83
  if (!(plugin == null ? void 0 : plugin.load) || !id)
66
84
  return callback(null, source, map);
67
- if (plugin.loadInclude && !plugin.loadInclude(id))
68
- return callback(null, source, map);
85
+ if (isVirtualModuleId(id, plugin))
86
+ id = decodeVirtualModuleId(id, plugin);
69
87
  const context = createContext(this);
70
88
  const res = await plugin.load.call(
71
89
  Object.assign(
72
90
  {},
73
- this._compilation && createBuildContext(this._compilation),
91
+ this._compilation && createBuildContext(this._compiler, this._compilation, this),
74
92
  context
75
93
  ),
76
94
  normalizeAbsolutePath(id)
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/rspack/loaders/transform.ts
@@ -35,11 +25,25 @@ __export(transform_exports, {
35
25
  module.exports = __toCommonJS(transform_exports);
36
26
 
37
27
  // src/rspack/context.ts
28
+ var import_path = require("path");
38
29
  var import_buffer = require("buffer");
39
- var import_webpack_sources = __toESM(require("webpack-sources"));
40
30
  var import_acorn = require("acorn");
41
- function createBuildContext(compilation) {
31
+ function createBuildContext(compiler, compilation, loaderContext) {
42
32
  return {
33
+ getNativeBuildContext() {
34
+ return {
35
+ framework: "rspack",
36
+ compiler,
37
+ compilation,
38
+ loaderContext
39
+ };
40
+ },
41
+ addWatchFile(file) {
42
+ compilation.fileDependencies.add((0, import_path.resolve)(process.cwd(), file));
43
+ },
44
+ getWatchFiles() {
45
+ return Array.from(compilation.fileDependencies);
46
+ },
43
47
  parse(code, opts = {}) {
44
48
  return import_acorn.Parser.parse(code, {
45
49
  sourceType: "module",
@@ -48,22 +52,17 @@ function createBuildContext(compilation) {
48
52
  ...opts
49
53
  });
50
54
  },
51
- addWatchFile() {
52
- },
53
55
  emitFile(emittedFile) {
54
56
  const outFileName = emittedFile.fileName || emittedFile.name;
55
57
  if (emittedFile.source && outFileName) {
58
+ const { sources } = compilation.compiler.webpack;
56
59
  compilation.emitAsset(
57
60
  outFileName,
58
- new import_webpack_sources.default.RawSource(
59
- // @ts-expect-error types mismatch
61
+ new sources.RawSource(
60
62
  typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
61
63
  )
62
64
  );
63
65
  }
64
- },
65
- getWatchFiles() {
66
- return [];
67
66
  }
68
67
  };
69
68
  }
@@ -101,7 +100,7 @@ async function transform(source, map) {
101
100
  const res = await plugin.transform.call(
102
101
  Object.assign(
103
102
  {},
104
- this._compilation && createBuildContext(this._compilation),
103
+ this._compilation && createBuildContext(this._compiler, this._compilation, this),
105
104
  context
106
105
  ),
107
106
  source,
@@ -111,6 +110,5 @@ async function transform(source, map) {
111
110
  callback(null, source, map);
112
111
  else if (typeof res !== "string")
113
112
  callback(null, res.code, map == null ? map : res.map || map);
114
- else
115
- callback(null, res, map);
113
+ else callback(null, res, map);
116
114
  }
@@ -1,9 +1,23 @@
1
1
  // src/rspack/context.ts
2
+ import { resolve } from "path";
2
3
  import { Buffer } from "buffer";
3
- import sources from "webpack-sources";
4
4
  import { Parser } from "acorn";
5
- function createBuildContext(compilation) {
5
+ function createBuildContext(compiler, compilation, loaderContext) {
6
6
  return {
7
+ getNativeBuildContext() {
8
+ return {
9
+ framework: "rspack",
10
+ compiler,
11
+ compilation,
12
+ loaderContext
13
+ };
14
+ },
15
+ addWatchFile(file) {
16
+ compilation.fileDependencies.add(resolve(process.cwd(), file));
17
+ },
18
+ getWatchFiles() {
19
+ return Array.from(compilation.fileDependencies);
20
+ },
7
21
  parse(code, opts = {}) {
8
22
  return Parser.parse(code, {
9
23
  sourceType: "module",
@@ -12,22 +26,17 @@ function createBuildContext(compilation) {
12
26
  ...opts
13
27
  });
14
28
  },
15
- addWatchFile() {
16
- },
17
29
  emitFile(emittedFile) {
18
30
  const outFileName = emittedFile.fileName || emittedFile.name;
19
31
  if (emittedFile.source && outFileName) {
32
+ const { sources } = compilation.compiler.webpack;
20
33
  compilation.emitAsset(
21
34
  outFileName,
22
35
  new sources.RawSource(
23
- // @ts-expect-error types mismatch
24
36
  typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
25
37
  )
26
38
  );
27
39
  }
28
- },
29
- getWatchFiles() {
30
- return [];
31
40
  }
32
41
  };
33
42
  }
@@ -65,7 +74,7 @@ async function transform(source, map) {
65
74
  const res = await plugin.transform.call(
66
75
  Object.assign(
67
76
  {},
68
- this._compilation && createBuildContext(this._compilation),
77
+ this._compilation && createBuildContext(this._compiler, this._compilation, this),
69
78
  context
70
79
  ),
71
80
  source,
@@ -75,8 +84,7 @@ async function transform(source, map) {
75
84
  callback(null, source, map);
76
85
  else if (typeof res !== "string")
77
86
  callback(null, res.code, map == null ? map : res.map || map);
78
- else
79
- callback(null, res, map);
87
+ else callback(null, res, map);
80
88
  }
81
89
  export {
82
90
  transform as default
@@ -1,5 +1,7 @@
1
1
  import { LoaderContext } from 'webpack';
2
2
 
3
- declare function load(this: LoaderContext<any>, source: string, map: any): Promise<void>;
3
+ declare function load(this: LoaderContext<{
4
+ unpluginName: string;
5
+ }>, source: string, map: any): Promise<void>;
4
6
 
5
7
  export { load as default };
@@ -1,5 +1,7 @@
1
1
  import { LoaderContext } from 'webpack';
2
2
 
3
- declare function load(this: LoaderContext<any>, source: string, map: any): Promise<void>;
3
+ declare function load(this: LoaderContext<{
4
+ unpluginName: string;
5
+ }>, source: string, map: any): Promise<void>;
4
6
 
5
7
  export { load as default };
@@ -34,13 +34,19 @@ __export(load_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(load_exports);
36
36
 
37
+ // node_modules/.pnpm/tsup@8.2.4_jiti@1.21.6_typescript@5.5.4/node_modules/tsup/assets/cjs_shims.js
38
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
39
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
+
37
41
  // src/webpack/context.ts
38
42
  var import_path = require("path");
39
43
  var import_buffer = require("buffer");
40
44
  var import_process = __toESM(require("process"));
41
- var import_webpack_sources = __toESM(require("webpack-sources"));
45
+ var import_module = require("module");
42
46
  var import_acorn = require("acorn");
43
- function createBuildContext(options, compilation) {
47
+ function createBuildContext(options, compiler, compilation, loaderContext) {
48
+ const require2 = (0, import_module.createRequire)(importMetaUrl);
49
+ const sources = require2("webpack-sources");
44
50
  return {
45
51
  parse(code, opts = {}) {
46
52
  return import_acorn.Parser.parse(code, {
@@ -60,7 +66,7 @@ function createBuildContext(options, compilation) {
60
66
  throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
61
67
  compilation.emitAsset(
62
68
  outFileName,
63
- import_webpack_sources.default ? new import_webpack_sources.default.RawSource(
69
+ sources ? new sources.RawSource(
64
70
  // @ts-expect-error types mismatch
65
71
  typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
66
72
  ) : {
@@ -72,6 +78,9 @@ function createBuildContext(options, compilation) {
72
78
  },
73
79
  getWatchFiles() {
74
80
  return options.getWatchFiles();
81
+ },
82
+ getNativeBuildContext() {
83
+ return { framework: "webpack", compiler, compilation, loaderContext };
75
84
  }
76
85
  };
77
86
  }
@@ -98,12 +107,19 @@ function normalizeAbsolutePath(path) {
98
107
  else
99
108
  return path;
100
109
  }
110
+ function resolveQuery(query) {
111
+ if (typeof query === "string") {
112
+ return new URLSearchParams(query).get("unpluginName");
113
+ } else {
114
+ return query.unpluginName;
115
+ }
116
+ }
101
117
 
102
118
  // src/webpack/loaders/load.ts
103
119
  async function load(source, map) {
104
120
  var _a;
105
121
  const callback = this.async();
106
- const { unpluginName } = this.query;
122
+ const unpluginName = resolveQuery(this.query);
107
123
  const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
108
124
  let id = this.resource;
109
125
  if (!(plugin == null ? void 0 : plugin.load) || !id)
@@ -112,14 +128,14 @@ async function load(source, map) {
112
128
  id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
113
129
  const context = createContext(this);
114
130
  const res = await plugin.load.call(
115
- { ...createBuildContext({
131
+ Object.assign({}, createBuildContext({
116
132
  addWatchFile: (file) => {
117
133
  this.addDependency(file);
118
134
  },
119
135
  getWatchFiles: () => {
120
136
  return this.getDependencies();
121
137
  }
122
- }, this._compilation), ...context },
138
+ }, this._compiler, this._compilation, this), context),
123
139
  normalizeAbsolutePath(id)
124
140
  );
125
141
  if (res == null)
@@ -2,9 +2,11 @@
2
2
  import { resolve } from "path";
3
3
  import { Buffer } from "buffer";
4
4
  import process from "process";
5
- import sources from "webpack-sources";
5
+ import { createRequire } from "module";
6
6
  import { Parser } from "acorn";
7
- function createBuildContext(options, compilation) {
7
+ function createBuildContext(options, compiler, compilation, loaderContext) {
8
+ const require2 = createRequire(import.meta.url);
9
+ const sources = require2("webpack-sources");
8
10
  return {
9
11
  parse(code, opts = {}) {
10
12
  return Parser.parse(code, {
@@ -36,6 +38,9 @@ function createBuildContext(options, compilation) {
36
38
  },
37
39
  getWatchFiles() {
38
40
  return options.getWatchFiles();
41
+ },
42
+ getNativeBuildContext() {
43
+ return { framework: "webpack", compiler, compilation, loaderContext };
39
44
  }
40
45
  };
41
46
  }
@@ -62,12 +67,19 @@ function normalizeAbsolutePath(path) {
62
67
  else
63
68
  return path;
64
69
  }
70
+ function resolveQuery(query) {
71
+ if (typeof query === "string") {
72
+ return new URLSearchParams(query).get("unpluginName");
73
+ } else {
74
+ return query.unpluginName;
75
+ }
76
+ }
65
77
 
66
78
  // src/webpack/loaders/load.ts
67
79
  async function load(source, map) {
68
80
  var _a;
69
81
  const callback = this.async();
70
- const { unpluginName } = this.query;
82
+ const unpluginName = resolveQuery(this.query);
71
83
  const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
72
84
  let id = this.resource;
73
85
  if (!(plugin == null ? void 0 : plugin.load) || !id)
@@ -76,14 +88,14 @@ async function load(source, map) {
76
88
  id = decodeURIComponent(id.slice(plugin.__virtualModulePrefix.length));
77
89
  const context = createContext(this);
78
90
  const res = await plugin.load.call(
79
- { ...createBuildContext({
91
+ Object.assign({}, createBuildContext({
80
92
  addWatchFile: (file) => {
81
93
  this.addDependency(file);
82
94
  },
83
95
  getWatchFiles: () => {
84
96
  return this.getDependencies();
85
97
  }
86
- }, this._compilation), ...context },
98
+ }, this._compiler, this._compilation, this), context),
87
99
  normalizeAbsolutePath(id)
88
100
  );
89
101
  if (res == null)
@@ -34,13 +34,19 @@ __export(transform_exports, {
34
34
  });
35
35
  module.exports = __toCommonJS(transform_exports);
36
36
 
37
+ // node_modules/.pnpm/tsup@8.2.4_jiti@1.21.6_typescript@5.5.4/node_modules/tsup/assets/cjs_shims.js
38
+ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
39
+ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
40
+
37
41
  // src/webpack/context.ts
38
42
  var import_path = require("path");
39
43
  var import_buffer = require("buffer");
40
44
  var import_process = __toESM(require("process"));
41
- var import_webpack_sources = __toESM(require("webpack-sources"));
45
+ var import_module = require("module");
42
46
  var import_acorn = require("acorn");
43
- function createBuildContext(options, compilation) {
47
+ function createBuildContext(options, compiler, compilation, loaderContext) {
48
+ const require2 = (0, import_module.createRequire)(importMetaUrl);
49
+ const sources = require2("webpack-sources");
44
50
  return {
45
51
  parse(code, opts = {}) {
46
52
  return import_acorn.Parser.parse(code, {
@@ -60,7 +66,7 @@ function createBuildContext(options, compilation) {
60
66
  throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
61
67
  compilation.emitAsset(
62
68
  outFileName,
63
- import_webpack_sources.default ? new import_webpack_sources.default.RawSource(
69
+ sources ? new sources.RawSource(
64
70
  // @ts-expect-error types mismatch
65
71
  typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
66
72
  ) : {
@@ -72,6 +78,9 @@ function createBuildContext(options, compilation) {
72
78
  },
73
79
  getWatchFiles() {
74
80
  return options.getWatchFiles();
81
+ },
82
+ getNativeBuildContext() {
83
+ return { framework: "webpack", compiler, compilation, loaderContext };
75
84
  }
76
85
  };
77
86
  }
@@ -90,30 +99,33 @@ function normalizeMessage(error) {
90
99
  return err;
91
100
  }
92
101
 
102
+ // src/utils.ts
103
+ function resolveQuery(query) {
104
+ if (typeof query === "string") {
105
+ return new URLSearchParams(query).get("unpluginName");
106
+ } else {
107
+ return query.unpluginName;
108
+ }
109
+ }
110
+
93
111
  // src/webpack/loaders/transform.ts
94
112
  async function transform(source, map) {
95
113
  var _a;
96
114
  const callback = this.async();
97
- let unpluginName;
98
- if (typeof this.query === "string") {
99
- const query = new URLSearchParams(this.query);
100
- unpluginName = query.get("unpluginName");
101
- } else {
102
- unpluginName = this.query.unpluginName;
103
- }
115
+ const unpluginName = resolveQuery(this.query);
104
116
  const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
105
117
  if (!(plugin == null ? void 0 : plugin.transform))
106
118
  return callback(null, source, map);
107
119
  const context = createContext(this);
108
120
  const res = await plugin.transform.call(
109
- { ...createBuildContext({
121
+ Object.assign({}, createBuildContext({
110
122
  addWatchFile: (file) => {
111
123
  this.addDependency(file);
112
124
  },
113
125
  getWatchFiles: () => {
114
126
  return this.getDependencies();
115
127
  }
116
- }, this._compilation), ...context },
128
+ }, this._compiler, this._compilation, this), context),
117
129
  source,
118
130
  this.resource
119
131
  );
@@ -2,9 +2,11 @@
2
2
  import { resolve } from "path";
3
3
  import { Buffer } from "buffer";
4
4
  import process from "process";
5
- import sources from "webpack-sources";
5
+ import { createRequire } from "module";
6
6
  import { Parser } from "acorn";
7
- function createBuildContext(options, compilation) {
7
+ function createBuildContext(options, compiler, compilation, loaderContext) {
8
+ const require2 = createRequire(import.meta.url);
9
+ const sources = require2("webpack-sources");
8
10
  return {
9
11
  parse(code, opts = {}) {
10
12
  return Parser.parse(code, {
@@ -36,6 +38,9 @@ function createBuildContext(options, compilation) {
36
38
  },
37
39
  getWatchFiles() {
38
40
  return options.getWatchFiles();
41
+ },
42
+ getNativeBuildContext() {
43
+ return { framework: "webpack", compiler, compilation, loaderContext };
39
44
  }
40
45
  };
41
46
  }
@@ -54,30 +59,33 @@ function normalizeMessage(error) {
54
59
  return err;
55
60
  }
56
61
 
62
+ // src/utils.ts
63
+ function resolveQuery(query) {
64
+ if (typeof query === "string") {
65
+ return new URLSearchParams(query).get("unpluginName");
66
+ } else {
67
+ return query.unpluginName;
68
+ }
69
+ }
70
+
57
71
  // src/webpack/loaders/transform.ts
58
72
  async function transform(source, map) {
59
73
  var _a;
60
74
  const callback = this.async();
61
- let unpluginName;
62
- if (typeof this.query === "string") {
63
- const query = new URLSearchParams(this.query);
64
- unpluginName = query.get("unpluginName");
65
- } else {
66
- unpluginName = this.query.unpluginName;
67
- }
75
+ const unpluginName = resolveQuery(this.query);
68
76
  const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
69
77
  if (!(plugin == null ? void 0 : plugin.transform))
70
78
  return callback(null, source, map);
71
79
  const context = createContext(this);
72
80
  const res = await plugin.transform.call(
73
- { ...createBuildContext({
81
+ Object.assign({}, createBuildContext({
74
82
  addWatchFile: (file) => {
75
83
  this.addDependency(file);
76
84
  },
77
85
  getWatchFiles: () => {
78
86
  return this.getDependencies();
79
87
  }
80
- }, this._compilation), ...context },
88
+ }, this._compiler, this._compilation, this), context),
81
89
  source,
82
90
  this.resource
83
91
  );