@datadog/esbuild-plugin 2.3.1-dev-0 → 2.3.1-dev-2
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/src/index.js +6 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +6 -2
- package/dist/src/index.mjs.map +1 -1
- package/dist/src/rspack/loaders/load.d.mts +5 -0
- package/dist/src/rspack/loaders/load.d.ts +5 -0
- package/dist/src/rspack/loaders/load.js +120 -0
- package/dist/src/rspack/loaders/load.mjs +87 -0
- package/dist/src/rspack/loaders/transform.d.mts +5 -0
- package/dist/src/rspack/loaders/transform.d.ts +5 -0
- package/dist/src/rspack/loaders/transform.js +116 -0
- package/dist/src/rspack/loaders/transform.mjs +83 -0
- package/dist/src/webpack/loaders/load.d.mts +5 -0
- package/dist/src/webpack/loaders/load.d.ts +5 -0
- package/dist/src/webpack/loaders/load.js +131 -0
- package/dist/src/webpack/loaders/load.mjs +98 -0
- package/dist/src/webpack/loaders/transform.d.mts +7 -0
- package/dist/src/webpack/loaders/transform.d.ts +7 -0
- package/dist/src/webpack/loaders/transform.js +126 -0
- package/dist/src/webpack/loaders/transform.mjs +93 -0
- package/package.json +1 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
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 });
|
|
17
|
+
}
|
|
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/loaders/transform.ts
|
|
31
|
+
var transform_exports = {};
|
|
32
|
+
__export(transform_exports, {
|
|
33
|
+
default: () => transform
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(transform_exports);
|
|
36
|
+
|
|
37
|
+
// src/webpack/context.ts
|
|
38
|
+
var import_path = require("path");
|
|
39
|
+
var import_buffer = require("buffer");
|
|
40
|
+
var import_process = __toESM(require("process"));
|
|
41
|
+
var import_webpack_sources = __toESM(require("webpack-sources"));
|
|
42
|
+
var import_acorn = require("acorn");
|
|
43
|
+
function createBuildContext(options, compilation) {
|
|
44
|
+
return {
|
|
45
|
+
parse(code, opts = {}) {
|
|
46
|
+
return import_acorn.Parser.parse(code, {
|
|
47
|
+
sourceType: "module",
|
|
48
|
+
ecmaVersion: "latest",
|
|
49
|
+
locations: true,
|
|
50
|
+
...opts
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
addWatchFile(id) {
|
|
54
|
+
options.addWatchFile((0, import_path.resolve)(import_process.default.cwd(), id));
|
|
55
|
+
},
|
|
56
|
+
emitFile(emittedFile) {
|
|
57
|
+
const outFileName = emittedFile.fileName || emittedFile.name;
|
|
58
|
+
if (emittedFile.source && outFileName) {
|
|
59
|
+
if (!compilation)
|
|
60
|
+
throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
|
|
61
|
+
compilation.emitAsset(
|
|
62
|
+
outFileName,
|
|
63
|
+
import_webpack_sources.default ? new import_webpack_sources.default.RawSource(
|
|
64
|
+
// @ts-expect-error types mismatch
|
|
65
|
+
typeof emittedFile.source === "string" ? emittedFile.source : import_buffer.Buffer.from(emittedFile.source)
|
|
66
|
+
) : {
|
|
67
|
+
source: () => emittedFile.source,
|
|
68
|
+
size: () => emittedFile.source.length
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
getWatchFiles() {
|
|
74
|
+
return options.getWatchFiles();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function createContext(loader) {
|
|
79
|
+
return {
|
|
80
|
+
error: (error) => loader.emitError(normalizeMessage(error)),
|
|
81
|
+
warn: (message) => loader.emitWarning(normalizeMessage(message))
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function normalizeMessage(error) {
|
|
85
|
+
const err = new Error(typeof error === "string" ? error : error.message);
|
|
86
|
+
if (typeof error === "object") {
|
|
87
|
+
err.stack = error.stack;
|
|
88
|
+
err.cause = error.meta;
|
|
89
|
+
}
|
|
90
|
+
return err;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/webpack/loaders/transform.ts
|
|
94
|
+
async function transform(source, map) {
|
|
95
|
+
var _a;
|
|
96
|
+
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
|
+
}
|
|
104
|
+
const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
|
|
105
|
+
if (!(plugin == null ? void 0 : plugin.transform))
|
|
106
|
+
return callback(null, source, map);
|
|
107
|
+
const context = createContext(this);
|
|
108
|
+
const res = await plugin.transform.call(
|
|
109
|
+
{ ...createBuildContext({
|
|
110
|
+
addWatchFile: (file) => {
|
|
111
|
+
this.addDependency(file);
|
|
112
|
+
},
|
|
113
|
+
getWatchFiles: () => {
|
|
114
|
+
return this.getDependencies();
|
|
115
|
+
}
|
|
116
|
+
}, this._compilation), ...context },
|
|
117
|
+
source,
|
|
118
|
+
this.resource
|
|
119
|
+
);
|
|
120
|
+
if (res == null)
|
|
121
|
+
callback(null, source, map);
|
|
122
|
+
else if (typeof res !== "string")
|
|
123
|
+
callback(null, res.code, map == null ? map : res.map || map);
|
|
124
|
+
else
|
|
125
|
+
callback(null, res, map);
|
|
126
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// src/webpack/context.ts
|
|
2
|
+
import { resolve } from "path";
|
|
3
|
+
import { Buffer } from "buffer";
|
|
4
|
+
import process from "process";
|
|
5
|
+
import sources from "webpack-sources";
|
|
6
|
+
import { Parser } from "acorn";
|
|
7
|
+
function createBuildContext(options, compilation) {
|
|
8
|
+
return {
|
|
9
|
+
parse(code, opts = {}) {
|
|
10
|
+
return Parser.parse(code, {
|
|
11
|
+
sourceType: "module",
|
|
12
|
+
ecmaVersion: "latest",
|
|
13
|
+
locations: true,
|
|
14
|
+
...opts
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
addWatchFile(id) {
|
|
18
|
+
options.addWatchFile(resolve(process.cwd(), id));
|
|
19
|
+
},
|
|
20
|
+
emitFile(emittedFile) {
|
|
21
|
+
const outFileName = emittedFile.fileName || emittedFile.name;
|
|
22
|
+
if (emittedFile.source && outFileName) {
|
|
23
|
+
if (!compilation)
|
|
24
|
+
throw new Error("unplugin/webpack: emitFile outside supported hooks (buildStart, buildEnd, load, transform, watchChange)");
|
|
25
|
+
compilation.emitAsset(
|
|
26
|
+
outFileName,
|
|
27
|
+
sources ? new sources.RawSource(
|
|
28
|
+
// @ts-expect-error types mismatch
|
|
29
|
+
typeof emittedFile.source === "string" ? emittedFile.source : Buffer.from(emittedFile.source)
|
|
30
|
+
) : {
|
|
31
|
+
source: () => emittedFile.source,
|
|
32
|
+
size: () => emittedFile.source.length
|
|
33
|
+
}
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
getWatchFiles() {
|
|
38
|
+
return options.getWatchFiles();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function createContext(loader) {
|
|
43
|
+
return {
|
|
44
|
+
error: (error) => loader.emitError(normalizeMessage(error)),
|
|
45
|
+
warn: (message) => loader.emitWarning(normalizeMessage(message))
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
function normalizeMessage(error) {
|
|
49
|
+
const err = new Error(typeof error === "string" ? error : error.message);
|
|
50
|
+
if (typeof error === "object") {
|
|
51
|
+
err.stack = error.stack;
|
|
52
|
+
err.cause = error.meta;
|
|
53
|
+
}
|
|
54
|
+
return err;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/webpack/loaders/transform.ts
|
|
58
|
+
async function transform(source, map) {
|
|
59
|
+
var _a;
|
|
60
|
+
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
|
+
}
|
|
68
|
+
const plugin = (_a = this._compiler) == null ? void 0 : _a.$unpluginContext[unpluginName];
|
|
69
|
+
if (!(plugin == null ? void 0 : plugin.transform))
|
|
70
|
+
return callback(null, source, map);
|
|
71
|
+
const context = createContext(this);
|
|
72
|
+
const res = await plugin.transform.call(
|
|
73
|
+
{ ...createBuildContext({
|
|
74
|
+
addWatchFile: (file) => {
|
|
75
|
+
this.addDependency(file);
|
|
76
|
+
},
|
|
77
|
+
getWatchFiles: () => {
|
|
78
|
+
return this.getDependencies();
|
|
79
|
+
}
|
|
80
|
+
}, this._compilation), ...context },
|
|
81
|
+
source,
|
|
82
|
+
this.resource
|
|
83
|
+
);
|
|
84
|
+
if (res == null)
|
|
85
|
+
callback(null, source, map);
|
|
86
|
+
else if (typeof res !== "string")
|
|
87
|
+
callback(null, res.code, map == null ? map : res.map || map);
|
|
88
|
+
else
|
|
89
|
+
callback(null, res, map);
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
transform as default
|
|
93
|
+
};
|