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