@sentry/bundler-plugins 11.0.0-beta.2 → 11.0.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/build/cjs/core/{component-annotation-vite-ast.js → component-annotation-oxc-ast.js} +1 -1
- package/build/cjs/core/component-annotation-oxc-ast.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite-fragments.js → component-annotation-oxc-fragments.js} +13 -13
- package/build/cjs/core/component-annotation-oxc-fragments.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite-jsx.js → component-annotation-oxc-jsx.js} +5 -5
- package/build/cjs/core/component-annotation-oxc-jsx.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js} +24 -24
- package/build/cjs/core/component-annotation-oxc-walk.js.map +1 -0
- package/build/cjs/core/{component-annotation-vite.js → component-annotation-oxc.js} +27 -11
- package/build/cjs/core/component-annotation-oxc.js.map +1 -0
- package/build/cjs/core/debug-id-upload.js +77 -2
- package/build/cjs/core/debug-id-upload.js.map +1 -1
- package/build/cjs/core/index.js +2 -0
- package/build/cjs/core/index.js.map +1 -1
- package/build/cjs/core/sentry/telemetry.js +4 -1
- package/build/cjs/core/sentry/telemetry.js.map +1 -1
- package/build/cjs/core/version.js +1 -1
- package/build/cjs/core/version.js.map +1 -1
- package/build/cjs/esbuild/index.js +17 -2
- package/build/cjs/esbuild/index.js.map +1 -1
- package/build/cjs/rollup/index.js +33 -22
- package/build/cjs/rollup/index.js.map +1 -1
- package/build/cjs/webpack/index.js +200 -11
- package/build/cjs/webpack/index.js.map +1 -1
- package/build/esm/core/{component-annotation-vite-ast.js → component-annotation-oxc-ast.js} +1 -1
- package/build/esm/core/component-annotation-oxc-ast.js.map +1 -0
- package/build/esm/core/{component-annotation-vite-fragments.js → component-annotation-oxc-fragments.js} +3 -3
- package/build/esm/core/component-annotation-oxc-fragments.js.map +1 -0
- package/build/esm/core/{component-annotation-vite-jsx.js → component-annotation-oxc-jsx.js} +2 -2
- package/build/esm/core/component-annotation-oxc-jsx.js.map +1 -0
- package/build/esm/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js} +6 -6
- package/build/esm/core/component-annotation-oxc-walk.js.map +1 -0
- package/build/esm/core/{component-annotation-vite.js → component-annotation-oxc.js} +25 -10
- package/build/esm/core/component-annotation-oxc.js.map +1 -0
- package/build/esm/core/debug-id-upload.js +76 -3
- package/build/esm/core/debug-id-upload.js.map +1 -1
- package/build/esm/core/index.js +1 -1
- package/build/esm/core/index.js.map +1 -1
- package/build/esm/core/sentry/telemetry.js +4 -1
- package/build/esm/core/sentry/telemetry.js.map +1 -1
- package/build/esm/core/version.js +1 -1
- package/build/esm/core/version.js.map +1 -1
- package/build/esm/esbuild/index.js +19 -4
- package/build/esm/esbuild/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/esm/rollup/index.js +34 -23
- package/build/esm/rollup/index.js.map +1 -1
- package/build/esm/webpack/index.js +186 -11
- package/build/esm/webpack/index.js.map +1 -1
- package/build/types/core/{component-annotation-vite-ast.d.ts → component-annotation-oxc-ast.d.ts} +1 -1
- package/build/types/core/component-annotation-oxc-ast.d.ts.map +1 -0
- package/build/types/core/{component-annotation-vite-fragments.d.ts → component-annotation-oxc-fragments.d.ts} +2 -2
- package/build/types/core/component-annotation-oxc-fragments.d.ts.map +1 -0
- package/build/types/core/{component-annotation-vite-jsx.d.ts → component-annotation-oxc-jsx.d.ts} +2 -2
- package/build/types/core/component-annotation-oxc-jsx.d.ts.map +1 -0
- package/build/types/core/component-annotation-oxc-walk.d.ts +3 -0
- package/build/types/core/component-annotation-oxc-walk.d.ts.map +1 -0
- package/build/types/core/component-annotation-oxc.d.ts +7 -0
- package/build/types/core/component-annotation-oxc.d.ts.map +1 -0
- package/build/types/core/debug-id-upload.d.ts +28 -0
- package/build/types/core/debug-id-upload.d.ts.map +1 -1
- package/build/types/core/index.d.ts +1 -1
- package/build/types/core/index.d.ts.map +1 -1
- package/build/types/core/sentry/telemetry.d.ts.map +1 -1
- package/build/types/core/types.d.ts +7 -2
- package/build/types/core/types.d.ts.map +1 -1
- package/build/types/core/version.d.ts +1 -1
- package/build/types/core/version.d.ts.map +1 -1
- package/build/types/esbuild/index.d.ts.map +1 -1
- package/build/types/rollup/index.d.ts +17 -26
- package/build/types/rollup/index.d.ts.map +1 -1
- package/build/types/webpack/index.d.ts +14 -2
- package/build/types/webpack/index.d.ts.map +1 -1
- package/package.json +4 -9
- package/build/cjs/core/component-annotation-vite-ast.js.map +0 -1
- package/build/cjs/core/component-annotation-vite-fragments.js.map +0 -1
- package/build/cjs/core/component-annotation-vite-jsx.js.map +0 -1
- package/build/cjs/core/component-annotation-vite-walk.js.map +0 -1
- package/build/cjs/core/component-annotation-vite.js.map +0 -1
- package/build/cjs/webpack/webpack4and5.js +0 -185
- package/build/cjs/webpack/webpack4and5.js.map +0 -1
- package/build/cjs/webpack/webpack5.js +0 -9
- package/build/cjs/webpack/webpack5.js.map +0 -1
- package/build/esm/core/component-annotation-vite-ast.js.map +0 -1
- package/build/esm/core/component-annotation-vite-fragments.js.map +0 -1
- package/build/esm/core/component-annotation-vite-jsx.js.map +0 -1
- package/build/esm/core/component-annotation-vite-walk.js.map +0 -1
- package/build/esm/core/component-annotation-vite.js.map +0 -1
- package/build/esm/webpack/webpack4and5.js +0 -168
- package/build/esm/webpack/webpack4and5.js.map +0 -1
- package/build/esm/webpack/webpack5.js +0 -7
- package/build/esm/webpack/webpack5.js.map +0 -1
- package/build/types/core/component-annotation-vite-ast.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite-fragments.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite-jsx.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite-walk.d.ts +0 -3
- package/build/types/core/component-annotation-vite-walk.d.ts.map +0 -1
- package/build/types/core/component-annotation-vite.d.ts +0 -6
- package/build/types/core/component-annotation-vite.d.ts.map +0 -1
- package/build/types/webpack/webpack4and5.d.ts +0 -99
- package/build/types/webpack/webpack4and5.d.ts.map +0 -1
- package/build/types/webpack/webpack5.d.ts +0 -4
- package/build/types/webpack/webpack5.d.ts.map +0 -1
|
@@ -1,23 +1,212 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const index = require('../core/index.js');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const node_url = require('node:url');
|
|
4
6
|
const node_module = require('node:module');
|
|
7
|
+
const node_crypto = require('node:crypto');
|
|
8
|
+
const buildPluginManager = require('../core/build-plugin-manager.js');
|
|
9
|
+
const utils = require('../core/utils.js');
|
|
10
|
+
const debugIdUpload = require('../core/debug-id-upload.js');
|
|
5
11
|
|
|
6
12
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
|
-
function
|
|
13
|
+
function _interopNamespace(e) {
|
|
14
|
+
if (e && e.__esModule) return e;
|
|
15
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
16
|
+
if (e) {
|
|
17
|
+
for (const k in e) {
|
|
18
|
+
n[k] = e[k];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
n.default = e;
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
26
|
+
|
|
27
|
+
const _req = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('webpack/index.js', document.baseURI).href)));
|
|
28
|
+
let COMPONENT_ANNOTATION_LOADER;
|
|
29
|
+
try {
|
|
30
|
+
COMPONENT_ANNOTATION_LOADER = _req.resolve("@sentry/bundler-plugins/webpack-loader");
|
|
31
|
+
} catch {
|
|
32
|
+
const dirname = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('webpack/index.js', document.baseURI).href))));
|
|
33
|
+
COMPONENT_ANNOTATION_LOADER = path__namespace.resolve(dirname, "component-annotation-transform.js");
|
|
34
|
+
}
|
|
35
|
+
function getWebpackMajorVersion() {
|
|
8
36
|
try {
|
|
9
|
-
|
|
37
|
+
const webpack = _req("webpack");
|
|
38
|
+
const version = webpack.version ?? webpack.default?.version;
|
|
39
|
+
return version?.split(".")[0];
|
|
10
40
|
} catch {
|
|
11
|
-
return
|
|
41
|
+
return void 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function addDebugIdsToAssets(compilation, RawSource) {
|
|
45
|
+
for (const asset of compilation.getAssets()) {
|
|
46
|
+
if (!index.isJsFile(asset.name)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const bundleSource = asset.source.source().toString();
|
|
50
|
+
const relatedSourceMap = asset.info.related?.sourceMap;
|
|
51
|
+
const sourceMapName = typeof relatedSourceMap === "string" ? relatedSourceMap : `${asset.name}.map`;
|
|
52
|
+
const sourceMapAsset = compilation.getAsset(sourceMapName);
|
|
53
|
+
const stamped = debugIdUpload.stampDebugId(bundleSource, sourceMapAsset?.source.source().toString());
|
|
54
|
+
if (!stamped) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
compilation.updateAsset(asset.name, new RawSource(stamped.bundleSource));
|
|
58
|
+
if (stamped.sourceMapSource !== void 0) {
|
|
59
|
+
compilation.updateAsset(sourceMapName, new RawSource(stamped.sourceMapSource));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function createSentryWebpackPlugin(userOptions = {}) {
|
|
64
|
+
const sentryBuildPluginManager = buildPluginManager.createSentryBuildPluginManager(userOptions, {
|
|
65
|
+
loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? "[sentry-webpack-plugin]",
|
|
66
|
+
buildTool: "webpack",
|
|
67
|
+
buildToolMajorVersion: getWebpackMajorVersion()
|
|
68
|
+
});
|
|
69
|
+
const {
|
|
70
|
+
logger,
|
|
71
|
+
normalizedOptions: options,
|
|
72
|
+
bundleSizeOptimizationReplacementValues: replacementValues,
|
|
73
|
+
bundleMetadata,
|
|
74
|
+
createDependencyOnBuildArtifacts
|
|
75
|
+
} = sentryBuildPluginManager;
|
|
76
|
+
if (options.disable) {
|
|
77
|
+
return {
|
|
78
|
+
apply() {
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
if (process.cwd().match(/\\node_modules\\|\/node_modules\//)) {
|
|
83
|
+
logger.warn("Running Sentry plugin from within a `node_modules` folder. Some features may not work.");
|
|
84
|
+
}
|
|
85
|
+
const sourcemapsEnabled = options.sourcemaps?.disable !== true;
|
|
86
|
+
const staticInjectionCode = new utils.CodeInjection();
|
|
87
|
+
if (!options.release.inject) {
|
|
88
|
+
logger.debug("Release injection disabled via `release.inject` option. Will not inject release.");
|
|
89
|
+
} else if (!options.release.name) {
|
|
90
|
+
logger.debug(
|
|
91
|
+
"No release name provided. Will not inject release. Please set the `release.name` option to identify your release."
|
|
92
|
+
);
|
|
93
|
+
} else {
|
|
94
|
+
staticInjectionCode.append(
|
|
95
|
+
utils.generateReleaseInjectorCode({
|
|
96
|
+
release: options.release.name,
|
|
97
|
+
injectBuildInformation: options._experiments.injectBuildInformation || false
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
if (Object.keys(bundleMetadata).length > 0) {
|
|
102
|
+
staticInjectionCode.append(utils.generateModuleMetadataInjectorCode(bundleMetadata));
|
|
12
103
|
}
|
|
104
|
+
const transformAnnotations = options.reactComponentAnnotation?.enabled ? index.createComponentNameAnnotateHooks(
|
|
105
|
+
options.reactComponentAnnotation?.ignoredComponents || [],
|
|
106
|
+
!!options.reactComponentAnnotation?._experimentalInjectIntoHtml
|
|
107
|
+
) : void 0;
|
|
108
|
+
const transformReplace = Object.keys(replacementValues).length > 0;
|
|
109
|
+
return {
|
|
110
|
+
apply(compiler) {
|
|
111
|
+
void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {
|
|
112
|
+
});
|
|
113
|
+
const { BannerPlugin, DefinePlugin } = compiler.webpack ?? {};
|
|
114
|
+
if (!staticInjectionCode.isEmpty() || sourcemapsEnabled) {
|
|
115
|
+
if (!BannerPlugin) {
|
|
116
|
+
logger.warn(
|
|
117
|
+
"BannerPlugin is not available. Skipping code injection. This usually means webpack is not properly configured."
|
|
118
|
+
);
|
|
119
|
+
} else {
|
|
120
|
+
compiler.options.plugins = compiler.options.plugins || [];
|
|
121
|
+
compiler.options.plugins.push(
|
|
122
|
+
new BannerPlugin({
|
|
123
|
+
raw: true,
|
|
124
|
+
include: /\.(js|ts|jsx|tsx|mjs|cjs)(\?[^?]*)?(#[^#]*)?$/,
|
|
125
|
+
banner: (arg) => {
|
|
126
|
+
const codeToInject = staticInjectionCode.clone();
|
|
127
|
+
if (sourcemapsEnabled) {
|
|
128
|
+
const hash = arg?.chunk?.contentHash?.javascript ?? arg?.chunk?.hash;
|
|
129
|
+
const debugId = hash ? utils.stringToUUID(hash) : node_crypto.randomUUID();
|
|
130
|
+
codeToInject.append(index.getDebugIdSnippet(debugId));
|
|
131
|
+
}
|
|
132
|
+
return codeToInject.code();
|
|
133
|
+
}
|
|
134
|
+
})
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (sourcemapsEnabled && options.sourcemaps?.disable === "disable-upload") {
|
|
139
|
+
const RawSource = compiler.webpack?.sources?.RawSource;
|
|
140
|
+
const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;
|
|
141
|
+
if (!RawSource) {
|
|
142
|
+
logger.warn(
|
|
143
|
+
"Webpack sources are not available. Skipping debug ID injection into emitted source maps. This usually means webpack is not properly configured."
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
compiler.hooks.thisCompilation.tap("sentry-webpack-plugin", (compilation) => {
|
|
147
|
+
compilation.hooks.processAssets.tap({ name: "sentry-webpack-plugin", stage }, () => {
|
|
148
|
+
addDebugIdsToAssets(compilation, RawSource);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (transformReplace && DefinePlugin) {
|
|
154
|
+
compiler.options.plugins = compiler.options.plugins || [];
|
|
155
|
+
compiler.options.plugins.push(new DefinePlugin(replacementValues));
|
|
156
|
+
}
|
|
157
|
+
if (transformAnnotations?.transform) {
|
|
158
|
+
compiler.options.module = compiler.options.module || {};
|
|
159
|
+
compiler.options.module.rules = compiler.options.module.rules || [];
|
|
160
|
+
compiler.options.module.rules.unshift({
|
|
161
|
+
test: /\.[jt]sx$/,
|
|
162
|
+
exclude: /node_modules/,
|
|
163
|
+
enforce: "pre",
|
|
164
|
+
use: [
|
|
165
|
+
{
|
|
166
|
+
loader: COMPONENT_ANNOTATION_LOADER,
|
|
167
|
+
options: {
|
|
168
|
+
transform: transformAnnotations.transform
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
compiler.hooks.afterEmit.tapAsync(
|
|
175
|
+
"sentry-webpack-plugin",
|
|
176
|
+
(compilation, callback) => {
|
|
177
|
+
const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
|
|
178
|
+
const upload = debugIdUpload.createDebugIdUploadFunction({ sentryBuildPluginManager });
|
|
179
|
+
const run = async () => {
|
|
180
|
+
try {
|
|
181
|
+
await sentryBuildPluginManager.createRelease();
|
|
182
|
+
if (sourcemapsEnabled && options.sourcemaps?.disable !== "disable-upload") {
|
|
183
|
+
const outputPath = compilation.outputOptions.path ?? path__namespace.resolve();
|
|
184
|
+
const buildArtifacts = Object.keys(compilation.assets).map((asset) => path__namespace.join(outputPath, asset));
|
|
185
|
+
await upload(buildArtifacts);
|
|
186
|
+
}
|
|
187
|
+
} finally {
|
|
188
|
+
freeGlobalDependencyOnBuildArtifacts();
|
|
189
|
+
await sentryBuildPluginManager.deleteArtifacts();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
run().then(
|
|
193
|
+
() => callback(),
|
|
194
|
+
(err) => callback(err)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
if (userOptions._experiments?.forceExitOnBuildCompletion && compiler.options.mode === "production") {
|
|
199
|
+
compiler.hooks.done.tap("sentry-webpack-plugin", () => {
|
|
200
|
+
setTimeout(() => {
|
|
201
|
+
logger.debug("Exiting process after debug file upload");
|
|
202
|
+
process.exit(0);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
};
|
|
13
208
|
}
|
|
14
|
-
const
|
|
15
|
-
const BannerPlugin = webpack.BannerPlugin ?? webpack.default?.BannerPlugin;
|
|
16
|
-
const DefinePlugin = webpack.DefinePlugin ?? webpack.default?.DefinePlugin;
|
|
17
|
-
const sentryWebpackPlugin = webpack4and5.sentryWebpackPluginFactory({
|
|
18
|
-
BannerPlugin,
|
|
19
|
-
DefinePlugin
|
|
20
|
-
});
|
|
209
|
+
const sentryWebpackPlugin = createSentryWebpackPlugin;
|
|
21
210
|
|
|
22
211
|
exports.sentryWebpackPlugin = sentryWebpackPlugin;
|
|
23
212
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/webpack/index.ts"],"sourcesContent":["import type { SentryWebpackPluginOptions } from './webpack4and5';\nimport { sentryWebpackPluginFactory } from './webpack4and5';\nimport { createRequire } from 'node:module';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype PluginClass = new (options: any) => unknown;\n\ntype WebpackModule = {\n BannerPlugin?: PluginClass;\n DefinePlugin?: PluginClass;\n default?: WebpackModule;\n};\n\n// `webpack` is an optional peer dependency. We require it lazily so the plugin doesn't\n// crash on load in bundlers that don't ship `webpack` (e.g. rspack) — those provide\n// the plugin classes via `compiler.webpack` at runtime instead.\nfunction loadWebpack(): WebpackModule {\n try {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Rollup transpiles import.meta for CJS\n return createRequire(import.meta.url)('webpack') as WebpackModule;\n } catch {\n return {};\n }\n}\n\nconst webpack = loadWebpack();\nconst BannerPlugin = webpack.BannerPlugin ?? webpack.default?.BannerPlugin;\nconst DefinePlugin = webpack.DefinePlugin ?? webpack.default?.DefinePlugin;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = sentryWebpackPluginFactory({\n BannerPlugin,\n DefinePlugin,\n});\n\nexport type { SentryWebpackPluginOptions };\n"],"names":["createRequire","sentryWebpackPluginFactory"],"mappings":";;;;;;AAgBA,SAAS,WAAA,GAA6B;AACpC,EAAA,IAAI;AAGF,IAAA,OAAOA,yBAAA,CAAc,kQAAe,CAAA,CAAE,SAAS,CAAA;AAAA,EACjD,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAC;AAAA,EACV;AACF;AAEA,MAAM,UAAU,WAAA,EAAY;AAC5B,MAAM,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAgB,OAAA,CAAQ,OAAA,EAAS,YAAA;AAC9D,MAAM,YAAA,GAAe,OAAA,CAAQ,YAAA,IAAgB,OAAA,CAAQ,OAAA,EAAS,YAAA;AAGvD,MAAM,sBAAqEC,uCAAA,CAA2B;AAAA,EAC3G,YAAA;AAAA,EACA;AACF,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/webpack/index.ts"],"sourcesContent":["import type { Options } from '../core/index';\nimport {\n createSentryBuildPluginManager,\n generateReleaseInjectorCode,\n generateModuleMetadataInjectorCode,\n stringToUUID,\n createComponentNameAnnotateHooks,\n CodeInjection,\n getDebugIdSnippet,\n createDebugIdUploadFunction,\n isJsFile,\n stampDebugId,\n} from '../core/index';\nimport * as path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { createRequire } from 'node:module';\nimport { randomUUID } from 'node:crypto';\n\nconst _req = createRequire(import.meta.url);\n\n// Resolve the loader path via the package's own exports.\n// This module may end up in a shared chunk (_chunks/) whose import.meta.url\n// does not point to the webpack/ directory where the transform file lives, so\n// a path-relative lookup would fail. Using require.resolve on the package export\n// always finds the correct installed file regardless of chunk placement.\nlet COMPONENT_ANNOTATION_LOADER: string;\ntry {\n COMPONENT_ANNOTATION_LOADER = _req.resolve('@sentry/bundler-plugins/webpack-loader');\n} catch {\n // Fallback for non-packaged environments (e.g., monorepo source runs without dist)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore Rollup transpiles import.meta for us for CJS\n const dirname = path.dirname(fileURLToPath(import.meta.url));\n // The Rollup build emits `.js` for both CJS and ESM, so the extension is the same in both.\n COMPONENT_ANNOTATION_LOADER = path.resolve(dirname, 'component-annotation-transform.js');\n}\n\ninterface BannerPluginCallbackArg {\n chunk?: {\n hash?: string;\n contentHash?: {\n javascript?: string;\n };\n };\n}\n\ntype PluginClass = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (options: any): unknown;\n};\n\ntype WebpackSource = {\n source: () => string | Buffer;\n};\n\ntype WebpackRawSource = {\n new (source: string): WebpackSource;\n};\n\ntype WebpackAsset = {\n name: string;\n source: WebpackSource;\n info: {\n related?: {\n sourceMap?: string | string[];\n };\n };\n};\n\ntype WebpackCompiler = {\n options: {\n plugins?: unknown[];\n mode?: string;\n module?: {\n rules?: unknown[];\n };\n };\n hooks: {\n thisCompilation: {\n tap: (name: string, callback: (compilation: WebpackCompilation) => void) => void;\n };\n afterEmit: {\n tapAsync: (name: string, callback: (compilation: WebpackCompilation, cb: () => void) => void) => void;\n };\n done: {\n tap: (name: string, callback: () => void) => void;\n };\n };\n webpack?: {\n BannerPlugin?: PluginClass;\n DefinePlugin?: PluginClass;\n Compilation?: {\n PROCESS_ASSETS_STAGE_DEV_TOOLING?: number;\n };\n sources?: {\n RawSource?: WebpackRawSource;\n };\n };\n};\n\ntype WebpackCompilation = {\n outputOptions: {\n path?: string;\n };\n assets: Record<string, unknown>;\n getAssets: () => WebpackAsset[];\n getAsset: (name: string) => WebpackAsset | undefined;\n updateAsset: (name: string, source: WebpackSource) => void;\n hooks: {\n processAssets: {\n tap: (options: { name: string; stage: number }, callback: () => void) => void;\n };\n };\n};\n\ntype WebpackModule = {\n version?: string;\n default?: { version?: string };\n};\n\n// Only used for telemetry; `webpack` is an optional peer dependency and may be absent (e.g. rspack).\nfunction getWebpackMajorVersion(): string | undefined {\n try {\n const webpack = _req('webpack') as WebpackModule;\n const version = webpack.version ?? webpack.default?.version;\n return version?.split('.')[0];\n } catch {\n return undefined;\n }\n}\n\n/**\n * Stamps each JS asset's debug ID into the asset itself and its source map asset.\n *\n * Runs after source maps have been generated, so the JS asset no longer needs to carry\n * source map information and can be replaced with a plain `RawSource`.\n */\nfunction addDebugIdsToAssets(compilation: WebpackCompilation, RawSource: WebpackRawSource): void {\n for (const asset of compilation.getAssets()) {\n if (!isJsFile(asset.name)) {\n continue;\n }\n\n const bundleSource = asset.source.source().toString();\n const relatedSourceMap = asset.info.related?.sourceMap;\n const sourceMapName = typeof relatedSourceMap === 'string' ? relatedSourceMap : `${asset.name}.map`;\n const sourceMapAsset = compilation.getAsset(sourceMapName);\n\n const stamped = stampDebugId(bundleSource, sourceMapAsset?.source.source().toString());\n if (!stamped) {\n continue;\n }\n\n compilation.updateAsset(asset.name, new RawSource(stamped.bundleSource));\n if (stamped.sourceMapSource !== undefined) {\n compilation.updateAsset(sourceMapName, new RawSource(stamped.sourceMapSource));\n }\n }\n}\n\nfunction createSentryWebpackPlugin(userOptions: SentryWebpackPluginOptions = {}) {\n const sentryBuildPluginManager = createSentryBuildPluginManager(userOptions, {\n loggerPrefix: userOptions._metaOptions?.loggerPrefixOverride ?? '[sentry-webpack-plugin]',\n buildTool: 'webpack',\n buildToolMajorVersion: getWebpackMajorVersion(),\n });\n\n const {\n logger,\n normalizedOptions: options,\n bundleSizeOptimizationReplacementValues: replacementValues,\n bundleMetadata,\n createDependencyOnBuildArtifacts,\n } = sentryBuildPluginManager;\n\n if (options.disable) {\n return {\n apply() {\n // noop plugin\n },\n };\n }\n\n if (process.cwd().match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n logger.warn('Running Sentry plugin from within a `node_modules` folder. Some features may not work.');\n }\n\n const sourcemapsEnabled = options.sourcemaps?.disable !== true;\n const staticInjectionCode = new CodeInjection();\n\n if (!options.release.inject) {\n logger.debug('Release injection disabled via `release.inject` option. Will not inject release.');\n } else if (!options.release.name) {\n logger.debug(\n 'No release name provided. Will not inject release. Please set the `release.name` option to identify your release.',\n );\n } else {\n staticInjectionCode.append(\n generateReleaseInjectorCode({\n release: options.release.name,\n injectBuildInformation: options._experiments.injectBuildInformation || false,\n }),\n );\n }\n\n if (Object.keys(bundleMetadata).length > 0) {\n staticInjectionCode.append(generateModuleMetadataInjectorCode(bundleMetadata));\n }\n\n const transformAnnotations = options.reactComponentAnnotation?.enabled\n ? createComponentNameAnnotateHooks(\n options.reactComponentAnnotation?.ignoredComponents || [],\n !!options.reactComponentAnnotation?._experimentalInjectIntoHtml,\n )\n : undefined;\n\n const transformReplace = Object.keys(replacementValues).length > 0;\n\n return {\n apply(compiler: WebpackCompiler) {\n void sentryBuildPluginManager.telemetry.emitBundlerPluginExecutionSignal().catch(() => {\n // Telemetry failures are acceptable\n });\n\n const { BannerPlugin, DefinePlugin } = compiler.webpack ?? {};\n\n // Add BannerPlugin for code injection (release, metadata, debug IDs)\n if (!staticInjectionCode.isEmpty() || sourcemapsEnabled) {\n if (!BannerPlugin) {\n logger.warn(\n 'BannerPlugin is not available. Skipping code injection. This usually means webpack is not properly configured.',\n );\n } else {\n compiler.options.plugins = compiler.options.plugins || [];\n compiler.options.plugins.push(\n new BannerPlugin({\n raw: true,\n include: /\\.(js|ts|jsx|tsx|mjs|cjs)(\\?[^?]*)?(#[^#]*)?$/,\n banner: (arg?: BannerPluginCallbackArg) => {\n const codeToInject = staticInjectionCode.clone();\n if (sourcemapsEnabled) {\n const hash = arg?.chunk?.contentHash?.javascript ?? arg?.chunk?.hash;\n const debugId = hash ? stringToUUID(hash) : randomUUID();\n codeToInject.append(getDebugIdSnippet(debugId));\n }\n return codeToInject.code();\n },\n }),\n );\n }\n }\n\n // The upload routine (which stamps debug IDs into temp copies of the artifacts) is skipped\n // with `disable-upload`, so the emitted artifacts get stamped in the asset pipeline instead.\n if (sourcemapsEnabled && options.sourcemaps?.disable === 'disable-upload') {\n const RawSource = compiler.webpack?.sources?.RawSource;\n // Right after source map generation (and thus after minification, which would strip the comment),\n // so later stages (real content hashing, subresource integrity) see the final assets.\n const stage = (compiler.webpack?.Compilation?.PROCESS_ASSETS_STAGE_DEV_TOOLING ?? 500) + 1;\n\n if (!RawSource) {\n logger.warn(\n 'Webpack sources are not available. Skipping debug ID injection into emitted source maps. This usually means webpack is not properly configured.',\n );\n } else {\n compiler.hooks.thisCompilation.tap('sentry-webpack-plugin', compilation => {\n compilation.hooks.processAssets.tap({ name: 'sentry-webpack-plugin', stage }, () => {\n addDebugIdsToAssets(compilation, RawSource);\n });\n });\n }\n }\n\n // Add DefinePlugin for bundle size optimizations\n if (transformReplace && DefinePlugin) {\n compiler.options.plugins = compiler.options.plugins || [];\n compiler.options.plugins.push(new DefinePlugin(replacementValues));\n }\n\n // Add component name annotation transform\n if (transformAnnotations?.transform) {\n compiler.options.module = compiler.options.module || {};\n compiler.options.module.rules = compiler.options.module.rules || [];\n compiler.options.module.rules.unshift({\n test: /\\.[jt]sx$/,\n exclude: /node_modules/,\n enforce: 'pre',\n use: [\n {\n loader: COMPONENT_ANNOTATION_LOADER,\n options: {\n transform: transformAnnotations.transform,\n },\n },\n ],\n });\n }\n\n compiler.hooks.afterEmit.tapAsync(\n 'sentry-webpack-plugin',\n (compilation: WebpackCompilation, callback: (err?: Error) => void) => {\n const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();\n const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });\n\n const run = async (): Promise<void> => {\n try {\n await sentryBuildPluginManager.createRelease();\n if (sourcemapsEnabled && options.sourcemaps?.disable !== 'disable-upload') {\n const outputPath = compilation.outputOptions.path ?? path.resolve();\n const buildArtifacts = Object.keys(compilation.assets).map(asset => path.join(outputPath, asset));\n await upload(buildArtifacts);\n }\n } finally {\n freeGlobalDependencyOnBuildArtifacts();\n await sentryBuildPluginManager.deleteArtifacts();\n }\n };\n\n run().then(\n () => callback(),\n (err: Error) => callback(err),\n );\n },\n );\n\n if (userOptions._experiments?.forceExitOnBuildCompletion && compiler.options.mode === 'production') {\n compiler.hooks.done.tap('sentry-webpack-plugin', () => {\n setTimeout(() => {\n logger.debug('Exiting process after debug file upload');\n process.exit(0);\n });\n });\n }\n },\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = createSentryWebpackPlugin;\n\nexport type SentryWebpackPluginOptions = Options & {\n _experiments?: Options['_experiments'] & {\n /**\n * If enabled, the webpack plugin will exit the build process after the build completes.\n * Use this with caution, as it will terminate the process.\n *\n * More information: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/345\n *\n * @default false\n */\n forceExitOnBuildCompletion?: boolean;\n };\n};\n"],"names":["createRequire","path","fileURLToPath","isJsFile","stampDebugId","createSentryBuildPluginManager","CodeInjection","generateReleaseInjectorCode","generateModuleMetadataInjectorCode","createComponentNameAnnotateHooks","stringToUUID","randomUUID","getDebugIdSnippet","createDebugIdUploadFunction"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAM,IAAA,GAAOA,yBAAA,CAAc,kQAAe,CAAA;AAO1C,IAAI,2BAAA;AACJ,IAAI;AACF,EAAA,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AC7C,cAAA,IAAI,iBAAA,IAAqB,OAAA,CAAQ,UAAA,EAAY,OAAA,KAAY,gBAAA,EAAkB;AACzE,gBAAA,MAAM,UAAA,GAAa,WAAA,CAAY,aAAA,CAAc,IAAA,IAAQZ,gBAAK,OAAA,EAAQ;AAClE,gBAAA,MAAM,cAAA,GAAiB,MAAA,CAAO,IAAA,CAAK,WAAA,CAAY,MAAM,CAAA,CAAE,GAAA,CAAI,CAAA,KAAA,KAASA,eAAA,CAAK,IAAA,CAAK,UAAA,EAAY,KAAK,CAAC,CAAA;AAChG,gBAAA,MAAM,OAAO,cAAc,CAAA;AAAA,cAC7B;AAAA,YACF,CAAA,SAAE;AACA,cAAA,oCAAA,EAAqC;AACrC,cAAA,MAAM,yBAAyB,eAAA,EAAgB;AAAA,YACjD;AAAA,UACF,CAAA;AAEA,UAAA,GAAA,EAAI,CAAE,IAAA;AAAA,YACJ,MAAM,QAAA,EAAS;AAAA,YACf,CAAC,GAAA,KAAe,QAAA,CAAS,GAAG;AAAA,WAC9B;AAAA,QACF;AAAA,OACF;AAEA,MAAA,IAAI,YAAY,YAAA,EAAc,0BAAA,IAA8B,QAAA,CAAS,OAAA,CAAQ,SAAS,YAAA,EAAc;AAClG,QAAA,QAAA,CAAS,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,uBAAA,EAAyB,MAAM;AACrD,UAAA,UAAA,CAAW,MAAM;AACf,YAAA,MAAA,CAAO,MAAM,yCAAyC,CAAA;AACtD,YAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA,UAChB,CAAC,CAAA;AAAA,QACH,CAAC,CAAA;AAAA,MACH;AAAA,IACF;AAAA,GACF;AACF;AAGO,MAAM,mBAAA,GAAqE;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-ast.js","sources":["../../../src/core/component-annotation-oxc-ast.ts"],"sourcesContent":["import { isObjectLike } from '@sentry/core';\nimport type { SourceMap } from 'magic-string';\n\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\n\nexport { isObjectLike };\n\nexport type AstNode = {\n type: string;\n start?: number;\n end?: number;\n [key: string]: unknown;\n};\n\nexport type JSXElementNode = AstNode & {\n type: 'JSXElement';\n openingElement: JSXOpeningElementNode;\n children?: AstNode[];\n};\n\nexport type JSXFragmentNode = AstNode & {\n type: 'JSXFragment';\n children?: AstNode[];\n};\n\nexport type JSXRootNode = JSXElementNode | JSXFragmentNode;\n\nexport type JSXOpeningElementNode = AstNode & {\n type: 'JSXOpeningElement';\n name: AstNode;\n attributes?: AstNode[];\n selfClosing?: boolean;\n};\n\nexport type FragmentContext = {\n fragmentAliases: Set<string>;\n reactNamespaceAliases: Set<string>;\n};\n\nexport type AttributeInsertion = {\n offset: number;\n attributes: ComponentAnnotationAttribute[];\n};\n\nexport type ParseAstAsync = (code: string, options: { lang: 'jsx' | 'tsx' }) => Promise<unknown>;\n\nexport type MagicStringLike = {\n appendLeft(offset: number, content: string): void;\n toString(): string;\n generateMap?(options: {\n file?: string;\n source?: string;\n includeContent?: boolean;\n hires?: boolean | 'boundary';\n }): SourceMap | string;\n};\n\nexport type ComponentAnnotationTransformMeta = {\n magicString?: MagicStringLike;\n};\n\nexport type ComponentAnnotationTransformResult =\n | {\n code: string;\n map?: SourceMap | string;\n }\n | null\n | undefined;\n\nexport function isAstNode(value: unknown): value is AstNode {\n return isObjectLike(value) && typeof value.type === 'string';\n}\n\nexport function walkAst(node: unknown, visit: (node: AstNode) => void): void {\n if (!isAstNode(node)) {\n return;\n }\n\n visit(node);\n\n for (const value of Object.values(node)) {\n if (Array.isArray(value)) {\n for (const child of value) {\n walkAst(child, visit);\n }\n } else if (isAstNode(value)) {\n walkAst(value, visit);\n }\n }\n}\n"],"names":[],"mappings":";;;AAqEO,SAAS,UAAU,KAAA,EAAkC;AAC1D,EAAA,OAAO,YAAA,CAAa,KAAK,CAAA,IAAK,OAAO,MAAM,IAAA,KAAS,QAAA;AACtD;AAEO,SAAS,OAAA,CAAQ,MAAe,KAAA,EAAsC;AAC3E,EAAA,IAAI,CAAC,SAAA,CAAU,IAAI,CAAA,EAAG;AACpB,IAAA;AAAA,EACF;AAEA,EAAA,KAAA,CAAM,IAAI,CAAA;AAEV,EAAA,KAAA,MAAW,KAAA,IAAS,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA,EAAG;AACvC,IAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACxB,MAAA,KAAA,MAAW,SAAS,KAAA,EAAO;AACzB,QAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,MACtB;AAAA,IACF,CAAA,MAAA,IAAW,SAAA,CAAU,KAAK,CAAA,EAAG;AAC3B,MAAA,OAAA,CAAQ,OAAO,KAAK,CAAA;AAAA,IACtB;AAAA,EACF;AACF;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { walkAst, isAstNode } from './component-annotation-
|
|
2
|
-
import { getStringName } from './component-annotation-
|
|
1
|
+
import { walkAst, isAstNode } from './component-annotation-oxc-ast.js';
|
|
2
|
+
import { getStringName } from './component-annotation-oxc-jsx.js';
|
|
3
3
|
import { isObjectLike } from '@sentry/core';
|
|
4
4
|
|
|
5
5
|
function collectFragmentContext(ast) {
|
|
@@ -86,4 +86,4 @@ function isFragmentObjectPatternProperty(property) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export { collectFragmentContext };
|
|
89
|
-
//# sourceMappingURL=component-annotation-
|
|
89
|
+
//# sourceMappingURL=component-annotation-oxc-fragments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-fragments.js","sources":["../../../src/core/component-annotation-oxc-fragments.ts"],"sourcesContent":["import type { AstNode, FragmentContext } from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { getStringName } from './component-annotation-oxc-jsx';\n\nexport function collectFragmentContext(ast: AstNode): FragmentContext {\n const context: FragmentContext = {\n fragmentAliases: new Set<string>(),\n reactNamespaceAliases: new Set<string>(['React']),\n };\n\n walkAst(ast, node => {\n collectFragmentAliasesFromImport(node, context);\n collectFragmentAliasesFromVariableDeclarator(node, context);\n });\n\n return context;\n}\n\nfunction collectFragmentAliasesFromImport(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'ImportDeclaration' || !isObjectLike(node.source)) {\n return;\n }\n\n const source = node.source.value;\n if (source !== 'react' && source !== 'React') {\n return;\n }\n\n const specifiers = Array.isArray(node.specifiers) ? node.specifiers : [];\n\n for (const specifier of specifiers) {\n if (!isAstNode(specifier) || !isObjectLike(specifier.local)) {\n continue;\n }\n\n const localName = getStringName(specifier.local);\n if (!localName) {\n continue;\n }\n\n if (specifier.type === 'ImportDefaultSpecifier' || specifier.type === 'ImportNamespaceSpecifier') {\n context.reactNamespaceAliases.add(localName);\n } else if (isImportedReactFragment(specifier)) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction collectFragmentAliasesFromVariableDeclarator(node: AstNode, context: FragmentContext): void {\n if (node.type !== 'VariableDeclarator' || !isObjectLike(node.id) || !isObjectLike(node.init)) {\n return;\n }\n\n if (node.id.type === 'Identifier') {\n collectFragmentAliasFromIdentifier(node.id, node.init, context);\n return;\n }\n\n if (node.id.type === 'ObjectPattern') {\n collectFragmentAliasFromObjectPattern(node.id, node.init, context);\n }\n}\n\nfunction collectFragmentAliasFromIdentifier(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n const localName = getStringName(id);\n if (!localName) {\n return;\n }\n\n if (init.type === 'Identifier' && context.fragmentAliases.has(getStringName(init) ?? '')) {\n context.fragmentAliases.add(localName);\n }\n\n if (isReactFragmentMemberExpression(init, context)) {\n context.fragmentAliases.add(localName);\n }\n}\n\nfunction collectFragmentAliasFromObjectPattern(\n id: Record<string, unknown>,\n init: Record<string, unknown>,\n context: FragmentContext,\n): void {\n if (\n init.type !== 'Identifier' ||\n !context.reactNamespaceAliases.has(getStringName(init) ?? '') ||\n !Array.isArray(id.properties)\n ) {\n return;\n }\n\n for (const property of id.properties) {\n if (!isFragmentObjectPatternProperty(property)) {\n continue;\n }\n\n const localName = getStringName(property.value);\n if (localName) {\n context.fragmentAliases.add(localName);\n }\n }\n}\n\nfunction isImportedReactFragment(specifier: AstNode): boolean {\n return (\n specifier.type === 'ImportSpecifier' &&\n isObjectLike(specifier.imported) &&\n getStringName(specifier.imported) === 'Fragment'\n );\n}\n\nfunction isReactFragmentMemberExpression(init: Record<string, unknown>, context: FragmentContext): boolean {\n return (\n init.type === 'MemberExpression' &&\n isObjectLike(init.object) &&\n isObjectLike(init.property) &&\n context.reactNamespaceAliases.has(getStringName(init.object) ?? '') &&\n getStringName(init.property) === 'Fragment'\n );\n}\n\nfunction isFragmentObjectPatternProperty(property: unknown): property is { value: unknown } {\n return (\n isObjectLike(property) &&\n (property.type === 'Property' || property.type === 'ObjectProperty') &&\n isObjectLike(property.key) &&\n getStringName(property.key) === 'Fragment' &&\n isObjectLike(property.value)\n );\n}\n"],"names":[],"mappings":";;;;AAIO,SAAS,uBAAuB,GAAA,EAA+B;AACpE,EAAA,MAAM,OAAA,GAA2B;AAAA,IAC/B,eAAA,sBAAqB,GAAA,EAAY;AAAA,IACjC,qBAAA,kBAAuB,IAAI,GAAA,CAAY,CAAC,OAAO,CAAC;AAAA,GAClD;AAEA,EAAA,OAAA,CAAQ,KAAK,CAAA,IAAA,KAAQ;AACnB,IAAA,gCAAA,CAAiC,MAAM,OAAO,CAAA;AAC9C,IAAA,4CAAA,CAA6C,MAAM,OAAO,CAAA;AAAA,EAC5D,CAAC,CAAA;AAED,EAAA,OAAO,OAAA;AACT;AAEA,SAAS,gCAAA,CAAiC,MAAe,OAAA,EAAgC;AACvF,EAAA,IAAI,KAAK,IAAA,KAAS,mBAAA,IAAuB,CAAC,YAAA,CAAa,IAAA,CAAK,MAAM,CAAA,EAAG;AACnE,IAAA;AAAA,EACF;AAEA,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ACvC;AAAA,EACF;AACF;AAEA,SAAS,wBAAwB,SAAA,EAA6B;AAC5D,EAAA,OACE,SAAA,CAAU,IAAA,KAAS,iBAAA,IACnB,YAAA,CAAa,SAAA,CAAU,QAAQ,CAAA,IAC/B,aAAA,CAAc,SAAA,CAAU,QAAQ,CAAA,KAAM,UAAA;AAE1C;AAEA,SAAS,+BAAA,CAAgC,MAA+B,OAAA,EAAmC;AACzG,EAAA,OACE,IAAA,CAAK,SAAS,kBAAA,IACd,YAAA,CAAa,KAAK,MAAM,CAAA,IACxB,YAAA,CAAa,IAAA,CAAK,QAAQ,CAAA,IAC1B,QAAQ,qBAAA,CAAsB,GAAA,CAAI,aAAA,CAAc,IAAA,CAAK,MAAM,CAAA,IAAK,EAAE,CAAA,IAClE,aAAA,CAAc,IAAA,CAAK,QAAQ,CAAA,KAAM,UAAA;AAErC;AAEA,SAAS,gCAAgC,QAAA,EAAmD;AAC1F,EAAA,OACE,YAAA,CAAa,QAAQ,CAAA,KACpB,QAAA,CAAS,SAAS,UAAA,IAAc,QAAA,CAAS,SAAS,gBAAA,CAAA,IACnD,YAAA,CAAa,SAAS,GAAG,CAAA,IACzB,cAAc,QAAA,CAAS,GAAG,MAAM,UAAA,IAChC,YAAA,CAAa,SAAS,KAAK,CAAA;AAE/B;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getComponentAnnotationAttributes, WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME } from '../babel-plugin/component-annotation.js';
|
|
2
|
-
import { isAstNode } from './component-annotation-
|
|
2
|
+
import { isAstNode } from './component-annotation-oxc-ast.js';
|
|
3
3
|
import { isObjectLike } from '@sentry/core';
|
|
4
4
|
|
|
5
5
|
const UNKNOWN_ELEMENT_NAME = "unknown";
|
|
@@ -127,4 +127,4 @@ function getOrderedAttributes(attributeValues) {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
export { addPendingAttributes, getInsertionOffset, getJSXName, getStringName, isJSXElement, isJSXFragment, isJSXRoot, isReactFragment, toAttributeInsertions };
|
|
130
|
-
//# sourceMappingURL=component-annotation-
|
|
130
|
+
//# sourceMappingURL=component-annotation-oxc-jsx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-jsx.js","sources":["../../../src/core/component-annotation-oxc-jsx.ts"],"sourcesContent":["import {\n getComponentAnnotationAttributes,\n WEB_COMPONENT_NAME,\n WEB_ELEMENT_NAME,\n WEB_SOURCE_FILE_NAME,\n} from '../babel-plugin/component-annotation';\nimport type { ComponentAnnotationAttribute } from '../babel-plugin/component-annotation';\nimport type {\n AttributeInsertion,\n FragmentContext,\n JSXElementNode,\n JSXFragmentNode,\n JSXOpeningElementNode,\n JSXRootNode,\n} from './component-annotation-oxc-ast';\nimport { isAstNode, isObjectLike } from './component-annotation-oxc-ast';\n\nconst UNKNOWN_ELEMENT_NAME = 'unknown';\nconst WEB_ATTRIBUTE_NAMES = [WEB_ELEMENT_NAME, WEB_COMPONENT_NAME, WEB_SOURCE_FILE_NAME] as const;\nconst WEB_ATTRIBUTE_NAME_SET = new Set<string>(WEB_ATTRIBUTE_NAMES);\n\ntype PendingInsertion = {\n offset: number;\n attributeValues: Map<string, string>;\n};\n\nexport function isJSXElement(value: unknown): value is JSXElementNode {\n return isAstNode(value) && value.type === 'JSXElement';\n}\n\nexport function isJSXFragment(value: unknown): value is JSXFragmentNode {\n return isAstNode(value) && value.type === 'JSXFragment';\n}\n\nexport function isJSXRoot(value: unknown): value is JSXRootNode {\n return isJSXElement(value) || isJSXFragment(value);\n}\n\nexport function getStringName(node: unknown): string | null {\n return isObjectLike(node) && typeof node.name === 'string' ? node.name : null;\n}\n\nexport function getJSXName(name: unknown): string {\n if (!isAstNode(name)) {\n return UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXIdentifier') {\n return getStringName(name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXNamespacedName') {\n return getStringName(name.name) ?? UNKNOWN_ELEMENT_NAME;\n }\n\n if (name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(name.object);\n const propertyName = getJSXName(name.property);\n\n return `${objectName}.${propertyName}`;\n }\n\n return UNKNOWN_ELEMENT_NAME;\n}\n\nexport function getInsertionOffset(code: string, openingElement: JSXOpeningElementNode): number | null {\n if (typeof openingElement.end !== 'number') {\n return null;\n }\n\n if (!openingElement.selfClosing) {\n return openingElement.end - 1;\n }\n\n let offset = openingElement.end - 2;\n\n while (offset > 0 && /\\s/.test(code[offset] ?? '')) {\n offset -= 1;\n }\n\n return code[offset] === '/' ? offset : openingElement.end - 1;\n}\n\nexport function isReactFragment(openingElement: JSXOpeningElementNode, fragmentContext: FragmentContext): boolean {\n const elementName = getJSXName(openingElement.name);\n\n if (elementName === 'Fragment' || elementName === 'React.Fragment') {\n return true;\n }\n\n if (fragmentContext.fragmentAliases.has(elementName)) {\n return true;\n }\n\n if (isObjectLike(openingElement.name) && openingElement.name.type === 'JSXMemberExpression') {\n const objectName = getJSXName(openingElement.name.object);\n const propertyName = getJSXName(openingElement.name.property);\n\n return (\n propertyName === 'Fragment' &&\n (fragmentContext.reactNamespaceAliases.has(objectName) || fragmentContext.fragmentAliases.has(objectName))\n );\n }\n\n return false;\n}\n\nexport function addPendingAttributes(\n code: string,\n openingElement: JSXOpeningElementNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, PendingInsertion>,\n): void {\n const offset = getInsertionOffset(code, openingElement);\n if (offset === null) {\n return;\n }\n\n const pendingInsertion = insertionsByOffset.get(offset);\n const existingAttributes = getExistingAttributeNames(openingElement);\n\n for (const attributeName of pendingInsertion?.attributeValues.keys() ?? []) {\n existingAttributes.add(attributeName);\n }\n\n const attributes = getComponentAnnotationAttributes({\n attributeNames: [WEB_COMPONENT_NAME, WEB_ELEMENT_NAME, WEB_SOURCE_FILE_NAME],\n componentName,\n elementName: getJSXName(openingElement.name),\n existingAttributes,\n ignoredComponents,\n isFragment: isReactFragment(openingElement, fragmentContext),\n sourceFileName,\n });\n\n if (attributes.length === 0) {\n return;\n }\n\n const insertion =\n pendingInsertion ??\n insertionsByOffset\n .set(offset, {\n offset,\n attributeValues: new Map(),\n })\n .get(offset);\n\n for (const [name, value] of attributes) {\n insertion?.attributeValues.set(name, value);\n }\n}\n\nexport function toAttributeInsertions(insertionsByOffset: Map<number, PendingInsertion>): AttributeInsertion[] {\n return [...insertionsByOffset.values()].map(({ offset, attributeValues }) => ({\n offset,\n attributes: getOrderedAttributes(attributeValues),\n }));\n}\n\nfunction getExistingAttributeNames(openingElement: JSXOpeningElementNode): Set<string> {\n const names = new Set<string>();\n\n for (const attribute of openingElement.attributes ?? []) {\n if (attribute.type === 'JSXAttribute') {\n const name = getStringName(attribute.name);\n if (name) {\n names.add(name);\n }\n }\n }\n\n return names;\n}\n\nfunction getOrderedAttributes(attributeValues: ReadonlyMap<string, string>): ComponentAnnotationAttribute[] {\n const attributes: ComponentAnnotationAttribute[] = [];\n\n for (const name of WEB_ATTRIBUTE_NAMES) {\n const value = attributeValues.get(name);\n if (value) {\n attributes.push([name, value]);\n }\n }\n\n for (const [name, value] of attributeValues) {\n if (!WEB_ATTRIBUTE_NAME_SET.has(name)) {\n attributes.push([name, value]);\n }\n }\n\n return attributes;\n}\n"],"names":[],"mappings":";;;;AAiBA,MAAM,oBAAA,GAAuB,SAAA;AAC7B,MAAM,mBAAA,GAAsB,CAAC,gBAAA,EAAkB,kBAAA,EAAoB,oBAAoB,CAAA;AACvF,MAAM,sBAAA,GAAyB,IAAI,GAAA,CAAY,mBAAmB,CAAA;AAO3D,SAAS,aAAa,KAAA,EAAyC;AACpE,EAAA,OAAO,SAAA,CAAU,KAAK,CAAA,IAAK,KAAA,CAAM,IAAA,KAAS,YAAA;AAC5C;AAEO,SAAS,cAAc,KAAA,EAA0C;AACtE,EAAA,OAAO,SAAA,CAAU,KAAK,CAAA,I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AAA,EAAY,qBAAqB,eAAe;AAAA,GAClD,CAAE,CAAA;AACJ;AAEA,SAAS,0BAA0B,cAAA,EAAoD;AACrF,EAAA,MAAM,KAAA,uBAAY,GAAA,EAAY;AAE9B,EAAA,KAAA,MAAW,SAAA,IAAa,cAAA,CAAe,UAAA,IAAc,EAAC,EAAG;AACvD,IAAA,IAAI,SAAA,CAAU,SAAS,cAAA,EAAgB;AACrC,MAAA,MAAM,IAAA,GAAO,aAAA,CAAc,SAAA,CAAU,IAAI,CAAA;AACzC,MAAA,IAAI,IAAA,EAAM;AACR,QAAA,KAAA,CAAM,IAAI,IAAI,CAAA;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,qBAAqB,eAAA,EAA8E;AAC1G,EAAA,MAAM,aAA6C,EAAC;AAEpD,EAAA,KAAA,MAAW,QAAQ,mBAAA,EAAqB;AACtC,IAAA,MAAM,KAAA,GAAQ,eAAA,CAAgB,GAAA,CAAI,IAAI,CAAA;AACtC,IAAA,IAAI,KAAA,EAAO;AACT,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,CAAA,IAAK,eAAA,EAAiB;AAC3C,IAAA,IAAI,CAAC,sBAAA,CAAuB,GAAA,CAAI,IAAI,CAAA,EAAG;AACrC,MAAA,UAAA,CAAW,IAAA,CAAK,CAAC,IAAA,EAAM,KAAK,CAAC,CAAA;AAAA,IAC/B;AAAA,EACF;AAEA,EAAA,OAAO,UAAA;AACT;;;;"}
|
package/build/esm/core/{component-annotation-vite-walk.js → component-annotation-oxc-walk.js}
RENAMED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { toAttributeInsertions, isJSXElement, addPendingAttributes, isJSXRoot, getStringName } from './component-annotation-
|
|
2
|
-
import { walkAst, isAstNode } from './component-annotation-
|
|
3
|
-
import { collectFragmentContext } from './component-annotation-
|
|
1
|
+
import { toAttributeInsertions, isJSXElement, addPendingAttributes, isJSXRoot, getStringName } from './component-annotation-oxc-jsx.js';
|
|
2
|
+
import { walkAst, isAstNode } from './component-annotation-oxc-ast.js';
|
|
3
|
+
import { collectFragmentContext } from './component-annotation-oxc-fragments.js';
|
|
4
4
|
import { isObjectLike } from '@sentry/core';
|
|
5
5
|
|
|
6
|
-
function
|
|
6
|
+
function collectOxcComponentAnnotationInsertions(code, ast, ignoredComponents, sourceFileName) {
|
|
7
7
|
const fragmentContext = collectFragmentContext(ast);
|
|
8
8
|
const components = collectComponentJSXRoots(ast);
|
|
9
9
|
const insertionsByOffset = /* @__PURE__ */ new Map();
|
|
@@ -115,5 +115,5 @@ function processJSX(code, node, componentName, ignoredComponents, fragmentContex
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
export {
|
|
119
|
-
//# sourceMappingURL=component-annotation-
|
|
118
|
+
export { collectOxcComponentAnnotationInsertions };
|
|
119
|
+
//# sourceMappingURL=component-annotation-oxc-walk.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc-walk.js","sources":["../../../src/core/component-annotation-oxc-walk.ts"],"sourcesContent":["import type { AstNode, AttributeInsertion, FragmentContext, JSXRootNode } from './component-annotation-oxc-ast';\nimport {\n addPendingAttributes,\n getStringName,\n isJSXElement,\n isJSXRoot,\n toAttributeInsertions,\n} from './component-annotation-oxc-jsx';\nimport { isAstNode, isObjectLike, walkAst } from './component-annotation-oxc-ast';\nimport { collectFragmentContext } from './component-annotation-oxc-fragments';\n\ntype ComponentJSXRoots = { name: string; roots: JSXRootNode[] };\n\nexport function collectOxcComponentAnnotationInsertions(\n code: string,\n ast: AstNode,\n ignoredComponents: string[],\n sourceFileName: string,\n): AttributeInsertion[] {\n const fragmentContext = collectFragmentContext(ast);\n const components = collectComponentJSXRoots(ast);\n const insertionsByOffset = new Map<number, { offset: number; attributeValues: Map<string, string> }>();\n\n for (const component of components) {\n for (const root of component.roots) {\n processJSX(code, root, component.name, ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n\n return toAttributeInsertions(insertionsByOffset);\n}\n\nfunction getJSXRootsFromReturnArgument(argument: unknown): JSXRootNode[] {\n if (isJSXRoot(argument)) {\n return [argument];\n }\n\n if (isObjectLike(argument) && argument.type === 'ConditionalExpression') {\n return [argument.consequent, argument.alternate].filter(isJSXRoot);\n }\n\n return [];\n}\n\nfunction getReturnedJSXFromFunction(functionNode: AstNode): JSXRootNode[] {\n const body = functionNode.body;\n\n if (isJSXRoot(body)) {\n return [body];\n }\n\n if (!isObjectLike(body) || body.type !== 'BlockStatement') {\n return [];\n }\n\n const bodyStatements = Array.isArray(body.body) ? body.body : [];\n const returnStatement = bodyStatements.find(statement => {\n return isAstNode(statement) && statement.type === 'ReturnStatement';\n });\n\n return isObjectLike(returnStatement) ? getJSXRootsFromReturnArgument(returnStatement.argument) : [];\n}\n\nfunction pushFunctionComponent(components: ComponentJSXRoots[], nameNode: unknown, functionNode: AstNode): void {\n const name = getStringName(nameNode);\n\n if (name) {\n components.push({\n name,\n roots: getReturnedJSXFromFunction(functionNode),\n });\n }\n}\n\nfunction collectComponentJSXRoots(ast: AstNode): ComponentJSXRoots[] {\n const components: ComponentJSXRoots[] = [];\n\n walkAst(ast, node => {\n if (node.type === 'FunctionDeclaration' && isObjectLike(node.id)) {\n pushFunctionComponent(components, node.id, node);\n return;\n }\n\n if (node.type === 'VariableDeclarator' && isObjectLike(node.id)) {\n if (isAstNode(node.init) && node.init.type === 'ArrowFunctionExpression') {\n pushFunctionComponent(components, node.id, node.init);\n }\n\n return;\n }\n\n if (node.type === 'ClassDeclaration') {\n pushClassComponent(components, node);\n }\n });\n\n return components;\n}\n\nfunction pushClassComponent(components: ComponentJSXRoots[], node: AstNode): void {\n const renderMethodBody = getClassRenderMethodBody(node);\n\n if (!renderMethodBody) {\n return;\n }\n\n const roots: JSXRootNode[] = [];\n\n walkAst(renderMethodBody, child => {\n if (child.type === 'ReturnStatement' && isJSXRoot(child.argument)) {\n roots.push(child.argument);\n }\n });\n\n components.push({\n name: getStringName(node.id) ?? '',\n roots,\n });\n}\n\nfunction getClassRenderMethodBody(node: AstNode): AstNode | null {\n if (!isObjectLike(node.body) || !Array.isArray(node.body.body)) {\n return null;\n }\n\n const renderMethod = node.body.body.find(member => {\n return (\n isObjectLike(member) &&\n isObjectLike(member.key) &&\n getStringName(member.key) === 'render' &&\n (isObjectLike(member.value) || isObjectLike(member.body))\n );\n });\n\n if (!isObjectLike(renderMethod)) {\n return null;\n }\n\n if (isAstNode(renderMethod.value)) {\n return renderMethod.value;\n }\n\n return isAstNode(renderMethod) ? renderMethod : null;\n}\n\nfunction processJSX(\n code: string,\n node: JSXRootNode,\n componentName: string,\n ignoredComponents: string[],\n fragmentContext: FragmentContext,\n sourceFileName: string,\n insertionsByOffset: Map<number, { offset: number; attributeValues: Map<string, string> }>,\n): void {\n if (isJSXElement(node)) {\n addPendingAttributes(\n code,\n node.openingElement,\n componentName,\n ignoredComponents,\n fragmentContext,\n sourceFileName,\n insertionsByOffset,\n );\n }\n\n for (const child of node.children ?? []) {\n if (isJSXRoot(child)) {\n processJSX(code, child, '', ignoredComponents, fragmentContext, sourceFileName, insertionsByOffset);\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAaO,SAAS,uCAAA,CACd,IAAA,EACA,GAAA,EACA,iBAAA,EACA,cAAA,EACsB;AACtB,EAAA,MAAM,eAAA,GAAkB,uBAAuB,GAAG,CAAA;AAClD,EAAA,MAAM,UAAA,GAAa,yBAAyB,GAAG,CAAA;AAC/C,EAAA,MAAM,kBAAA,uBAAyB,GAAA,EAAsE;AAErG,EAAA,KAAA,MAAW,aAAa,UAAA,EAAY;AAClC,IAAA,KAAA,MAAW,IAAA,IAAQ,UAAU,KAAA,EAAO;AAClC,MAAA,UAAA,CAAW,MAAM,IAAA,EAAM,SAAA,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,oBAAA;AAAA,MACE,IAAA;AAAA,MACA,IAAA,CAAK,cAAA;AAAA,MACL,aAAA;AAAA,MACA,iBAAA;AAAA,MACA,eAAA;AAAA,MACA,cAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AAEA,EAAA,KAAA,MAAW,KAAA,IAAS,IAAA,CAAK,QAAA,IAAY,EAAC,EAAG;AACvC,IAAA,IAAI,SAAA,CAAU,KAAK,CAAA,EAAG;AACpB,MAAA,UAAA,CAAW,MAAM,KAAA,EAAO,EAAA,EAAI,iBAAA,EAAmB,eAAA,EAAiB,gBAAgB,kBAAkB,CAAA;AAAA,IACpG;AAAA,EACF;AACF;;;;"}
|
|
@@ -2,12 +2,27 @@ import path__default from 'node:path';
|
|
|
2
2
|
import MagicString from 'magic-string';
|
|
3
3
|
import { KNOWN_INCOMPATIBLE_PLUGINS } from '../babel-plugin/constants.js';
|
|
4
4
|
import { stripQueryAndHashFromPath } from './utils.js';
|
|
5
|
-
import { isAstNode } from './component-annotation-
|
|
6
|
-
import {
|
|
5
|
+
import { isAstNode } from './component-annotation-oxc-ast.js';
|
|
6
|
+
import { collectOxcComponentAnnotationInsertions } from './component-annotation-oxc-walk.js';
|
|
7
7
|
|
|
8
|
+
let oxcParseAstAsyncPromise;
|
|
9
|
+
function getOxcParseAstAsync() {
|
|
10
|
+
if (!oxcParseAstAsyncPromise) {
|
|
11
|
+
oxcParseAstAsyncPromise = import('oxc-parser').then(({ parse }) => {
|
|
12
|
+
return async (code, { lang }) => {
|
|
13
|
+
const { program, errors } = await parse(`component.${lang}`, code, { lang, preserveParens: false });
|
|
14
|
+
if (errors.length > 0) {
|
|
15
|
+
throw new Error(errors[0]?.message);
|
|
16
|
+
}
|
|
17
|
+
return program;
|
|
18
|
+
};
|
|
19
|
+
}).catch(() => null);
|
|
20
|
+
}
|
|
21
|
+
return oxcParseAstAsyncPromise;
|
|
22
|
+
}
|
|
8
23
|
const JSX_TAG_START_REGEXP = /<[$_\p{ID_Start}][$_\u200c\u200d\p{ID_Continue}.:-]*|<>/u;
|
|
9
24
|
const JSX_FILE_REGEXP = /\.[jt]sx$/;
|
|
10
|
-
function
|
|
25
|
+
function isAnnotationFile(idWithoutQueryAndHash) {
|
|
11
26
|
if (idWithoutQueryAndHash.match(/\\node_modules\\|\/node_modules\//)) {
|
|
12
27
|
return false;
|
|
13
28
|
}
|
|
@@ -37,9 +52,9 @@ function getMagicString(code, meta) {
|
|
|
37
52
|
}
|
|
38
53
|
return { magicString: new MagicString(code), isNative: false };
|
|
39
54
|
}
|
|
40
|
-
async function
|
|
55
|
+
async function annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta) {
|
|
41
56
|
const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);
|
|
42
|
-
if (!idWithoutQueryAndHash || !
|
|
57
|
+
if (!idWithoutQueryAndHash || !isAnnotationFile(idWithoutQueryAndHash) || !shouldTryParse(code) || shouldSkipIncompatibleFile(idWithoutQueryAndHash)) {
|
|
43
58
|
return null;
|
|
44
59
|
}
|
|
45
60
|
const ast = await parseAstAsync(code, {
|
|
@@ -48,7 +63,7 @@ async function annotateWithViteParser(code, id, ignoredComponents, parseAstAsync
|
|
|
48
63
|
if (!isAstNode(ast)) {
|
|
49
64
|
return void 0;
|
|
50
65
|
}
|
|
51
|
-
const insertions =
|
|
66
|
+
const insertions = collectOxcComponentAnnotationInsertions(
|
|
52
67
|
code,
|
|
53
68
|
ast,
|
|
54
69
|
ignoredComponents,
|
|
@@ -74,7 +89,7 @@ async function annotateWithViteParser(code, id, ignoredComponents, parseAstAsync
|
|
|
74
89
|
})
|
|
75
90
|
};
|
|
76
91
|
}
|
|
77
|
-
function
|
|
92
|
+
function createOxcComponentNameAnnotateHooks(ignoredComponents, getParseAstAsync) {
|
|
78
93
|
return {
|
|
79
94
|
async transform(code, id, meta) {
|
|
80
95
|
try {
|
|
@@ -82,7 +97,7 @@ function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsyn
|
|
|
82
97
|
if (!parseAstAsync) {
|
|
83
98
|
return void 0;
|
|
84
99
|
}
|
|
85
|
-
return await
|
|
100
|
+
return await annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta);
|
|
86
101
|
} catch {
|
|
87
102
|
return void 0;
|
|
88
103
|
}
|
|
@@ -90,5 +105,5 @@ function createViteComponentNameAnnotateHooks(ignoredComponents, getParseAstAsyn
|
|
|
90
105
|
};
|
|
91
106
|
}
|
|
92
107
|
|
|
93
|
-
export {
|
|
94
|
-
//# sourceMappingURL=component-annotation-
|
|
108
|
+
export { createOxcComponentNameAnnotateHooks, getOxcParseAstAsync };
|
|
109
|
+
//# sourceMappingURL=component-annotation-oxc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-annotation-oxc.js","sources":["../../../src/core/component-annotation-oxc.ts"],"sourcesContent":["import path from 'node:path';\n\nimport MagicString from 'magic-string';\n\nimport { KNOWN_INCOMPATIBLE_PLUGINS } from '../babel-plugin/constants';\nimport { stripQueryAndHashFromPath } from './utils';\nimport { isAstNode } from './component-annotation-oxc-ast';\nimport { collectOxcComponentAnnotationInsertions } from './component-annotation-oxc-walk';\nimport type {\n AttributeInsertion,\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n MagicStringLike,\n ParseAstAsync,\n} from './component-annotation-oxc-ast';\n\nexport type {\n ComponentAnnotationTransformMeta,\n ComponentAnnotationTransformResult,\n} from './component-annotation-oxc-ast';\n\nlet oxcParseAstAsyncPromise: Promise<ParseAstAsync | null> | undefined;\n\nexport function getOxcParseAstAsync(): Promise<ParseAstAsync | null> {\n if (!oxcParseAstAsyncPromise) {\n oxcParseAstAsyncPromise = import('oxc-parser')\n .then(({ parse }): ParseAstAsync => {\n return async (code, { lang }) => {\n // preserveParens: false matches the AST Vite 8 produces. The walker\n // does not look through ParenthesizedExpression nodes.\n const { program, errors } = await parse(`component.${lang}`, code, { lang, preserveParens: false });\n\n if (errors.length > 0) {\n throw new Error(errors[0]?.message);\n }\n\n return program;\n };\n })\n .catch(() => null);\n }\n\n return oxcParseAstAsyncPromise;\n}\n\n// Keep this as a superset of JSX tag starts Babel can annotate, because a miss suppresses Babel fallback.\nconst JSX_TAG_START_REGEXP = /<[$_\\p{ID_Start}][$_\\u200c\\u200d\\p{ID_Continue}.:-]*|<>/u;\nconst JSX_FILE_REGEXP = /\\.[jt]sx$/;\n\nfunction isAnnotationFile(idWithoutQueryAndHash: string): boolean {\n if (idWithoutQueryAndHash.match(/\\\\node_modules\\\\|\\/node_modules\\//)) {\n return false;\n }\n\n return JSX_FILE_REGEXP.test(idWithoutQueryAndHash);\n}\n\nfunction shouldTryParse(code: string): boolean {\n return JSX_TAG_START_REGEXP.test(code);\n}\n\nfunction shouldSkipIncompatibleFile(idWithoutQueryAndHash: string): boolean {\n return KNOWN_INCOMPATIBLE_PLUGINS.some(pluginName => {\n return (\n idWithoutQueryAndHash.includes(`/node_modules/${pluginName}/`) ||\n idWithoutQueryAndHash.includes(`\\\\node_modules\\\\${pluginName}\\\\`)\n );\n });\n}\n\nfunction escapeAttributeValue(value: string): string {\n return value.replace(/&/g, '&').replace(/\"/g, '"');\n}\n\nfunction makeAttributeText(\n code: string,\n insertionOffset: number,\n attributes: AttributeInsertion['attributes'],\n): string {\n const previousCharIsWhitespace = insertionOffset > 0 && /\\s/.test(code[insertionOffset - 1] ?? '');\n const prefix = previousCharIsWhitespace ? '' : ' ';\n const suffix = previousCharIsWhitespace && code[insertionOffset] === '/' ? ' ' : '';\n const attributeText = attributes.map(([name, value]) => `${name}=\"${escapeAttributeValue(value)}\"`).join(' ');\n\n return `${prefix}${attributeText}${suffix}`;\n}\n\nfunction getMagicString(\n code: string,\n meta?: ComponentAnnotationTransformMeta,\n): { magicString: MagicStringLike; isNative: boolean } {\n if (meta?.magicString) {\n return { magicString: meta.magicString, isNative: true };\n }\n\n return { magicString: new MagicString(code), isNative: false };\n}\n\nasync function annotateWithOxcParser(\n code: string,\n id: string,\n ignoredComponents: string[],\n parseAstAsync: ParseAstAsync,\n meta?: ComponentAnnotationTransformMeta,\n): Promise<ComponentAnnotationTransformResult> {\n const idWithoutQueryAndHash = stripQueryAndHashFromPath(id);\n\n if (\n !idWithoutQueryAndHash ||\n !isAnnotationFile(idWithoutQueryAndHash) ||\n !shouldTryParse(code) ||\n shouldSkipIncompatibleFile(idWithoutQueryAndHash)\n ) {\n return null;\n }\n\n const ast = await parseAstAsync(code, {\n lang: idWithoutQueryAndHash.endsWith('.jsx') ? 'jsx' : 'tsx',\n });\n\n // Fall through to the Babel fallback (return undefined, not null) when the parser yields an\n // unexpected result, mirroring the catch path — null would suppress Babel and drop annotations.\n if (!isAstNode(ast)) {\n return undefined;\n }\n\n const insertions = collectOxcComponentAnnotationInsertions(\n code,\n ast,\n ignoredComponents,\n path.basename(idWithoutQueryAndHash),\n );\n\n if (insertions.length === 0) {\n return null;\n }\n\n const { magicString, isNative } = getMagicString(code, meta);\n\n for (const insertion of insertions) {\n magicString.appendLeft(insertion.offset, makeAttributeText(code, insertion.offset, insertion.attributes));\n }\n\n if (isNative) {\n return { code: magicString as unknown as string };\n }\n\n return {\n code: magicString.toString(),\n map: magicString.generateMap?.({\n file: id,\n source: idWithoutQueryAndHash,\n includeContent: true,\n hires: true,\n }),\n };\n}\n\nexport function createOxcComponentNameAnnotateHooks(\n ignoredComponents: string[],\n getParseAstAsync: () => Promise<ParseAstAsync | null>,\n): {\n transform(\n code: string,\n id: string,\n meta?: ComponentAnnotationTransformMeta,\n ): Promise<ComponentAnnotationTransformResult>;\n} {\n return {\n async transform(code, id, meta) {\n try {\n const parseAstAsync = await getParseAstAsync();\n\n if (!parseAstAsync) {\n return undefined;\n }\n\n return await annotateWithOxcParser(code, id, ignoredComponents, parseAstAsync, meta);\n } catch {\n return undefined;\n }\n },\n };\n}\n"],"names":["path"],"mappings":";;;;;;;AAqBA,IAAI,uBAAA;AAEG,SAAS,mBAAA,GAAqD;AACnE,EAAA,IAAI,CAAC,uBAAA,EAAyB;AA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AAU,IAAA,EAAM,EAAA,EAAI,IAAA,EAAM;AAC9B,MAAA,IAAI;AACF,QAAA,MAAM,aAAA,GAAgB,MAAM,gBAAA,EAAiB;AAE7C,QAAA,IAAI,CAAC,aAAA,EAAe;AAClB,UAAA,OAAO,KAAA,CAAA;AAAA,QACT;AAEA,QAAA,OAAO,MAAM,qBAAA,CAAsB,IAAA,EAAM,EAAA,EAAI,iBAAA,EAAmB,eAAe,IAAI,CAAA;AAAA,MACrF,CAAA,CAAA,MAAQ;AACN,QAAA,OAAO,MAAA;AAAA,MACT;AAAA,IACF;AAAA,GACF;AACF;;;;"}
|
|
@@ -75,6 +75,80 @@ function addDebugIdToBundleSource(bundleSource, debugId) {
|
|
|
75
75
|
//# debugId=${debugId}`;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
function setDebugIdOnSourceMap(map, debugId) {
|
|
79
|
+
map["debug_id"] = debugId;
|
|
80
|
+
map["debugId"] = debugId;
|
|
81
|
+
}
|
|
82
|
+
function parseSourceMap(sourceMapSource) {
|
|
83
|
+
let map;
|
|
84
|
+
try {
|
|
85
|
+
map = JSON.parse(sourceMapSource);
|
|
86
|
+
} catch {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
return map && typeof map === "object" ? map : void 0;
|
|
90
|
+
}
|
|
91
|
+
function stampDebugId(bundleSource, sourceMapSource) {
|
|
92
|
+
const debugId = determineDebugIdFromBundleSource(bundleSource);
|
|
93
|
+
if (debugId === void 0) {
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
if (sourceMapSource === void 0) {
|
|
97
|
+
if (!bundleHasInlineSourceMap(bundleSource)) {
|
|
98
|
+
return void 0;
|
|
99
|
+
}
|
|
100
|
+
return { bundleSource: addDebugIdToBundleSource(bundleSource, debugId), sourceMapSource: void 0 };
|
|
101
|
+
}
|
|
102
|
+
const map = parseSourceMap(sourceMapSource);
|
|
103
|
+
if (!map) {
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
setDebugIdOnSourceMap(map, debugId);
|
|
107
|
+
return {
|
|
108
|
+
bundleSource: addDebugIdToBundleSource(bundleSource, debugId),
|
|
109
|
+
sourceMapSource: JSON.stringify(map)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function addDebugIdToEmittedArtifacts(bundleFilePath, logger, resolveSourceMapHook) {
|
|
113
|
+
let bundleSource;
|
|
114
|
+
try {
|
|
115
|
+
bundleSource = await fs__default.promises.readFile(bundleFilePath, "utf8");
|
|
116
|
+
} catch (e) {
|
|
117
|
+
logger.error(`Could not read bundle to stamp debug ID: ${bundleFilePath}`, e);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const sourceMapPath = await determineSourceMapPathFromBundle(
|
|
121
|
+
bundleFilePath,
|
|
122
|
+
bundleSource,
|
|
123
|
+
logger,
|
|
124
|
+
resolveSourceMapHook
|
|
125
|
+
);
|
|
126
|
+
let sourceMapSource;
|
|
127
|
+
if (sourceMapPath) {
|
|
128
|
+
try {
|
|
129
|
+
sourceMapSource = await fs__default.promises.readFile(sourceMapPath, "utf8");
|
|
130
|
+
} catch (e) {
|
|
131
|
+
logger.error(`Could not read source map to stamp debug ID: ${sourceMapPath}`, e);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
const stamped = stampDebugId(bundleSource, sourceMapSource);
|
|
136
|
+
if (!stamped) {
|
|
137
|
+
logger.debug(
|
|
138
|
+
`Could not stamp debug ID (no debug ID in bundle, no source map, or invalid source map): ${bundleFilePath}`
|
|
139
|
+
);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const writes = [fs__default.promises.writeFile(bundleFilePath, stamped.bundleSource, "utf8")];
|
|
143
|
+
if (sourceMapPath && stamped.sourceMapSource !== void 0) {
|
|
144
|
+
writes.push(fs__default.promises.writeFile(sourceMapPath, stamped.sourceMapSource, "utf8"));
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
await Promise.all(writes);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
logger.error(`Could not write debug ID into build artifacts: ${bundleFilePath}`, e);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
78
152
|
function bundleHasInlineSourceMap(bundleSource) {
|
|
79
153
|
return /^\s*\/\/# sourceMappingURL=data:/m.test(bundleSource);
|
|
80
154
|
}
|
|
@@ -133,8 +207,7 @@ async function prepareSourceMapForDebugIdUpload(sourceMapPath, targetPath, debug
|
|
|
133
207
|
let map;
|
|
134
208
|
try {
|
|
135
209
|
map = JSON.parse(sourceMapFileContent);
|
|
136
|
-
map
|
|
137
|
-
map["debugId"] = debugId;
|
|
210
|
+
setDebugIdOnSourceMap(map, debugId);
|
|
138
211
|
} catch {
|
|
139
212
|
logger.error(`Failed to parse source map for debug ID upload: ${sourceMapPath}`);
|
|
140
213
|
return;
|
|
@@ -161,5 +234,5 @@ function defaultRewriteSourcesHook(source) {
|
|
|
161
234
|
}
|
|
162
235
|
}
|
|
163
236
|
|
|
164
|
-
export { createDebugIdUploadFunction, defaultRewriteSourcesHook, determineSourceMapPathFromBundle, prepareBundleForDebugIdUpload };
|
|
237
|
+
export { addDebugIdToEmittedArtifacts, createDebugIdUploadFunction, defaultRewriteSourcesHook, determineSourceMapPathFromBundle, prepareBundleForDebugIdUpload, stampDebugId };
|
|
165
238
|
//# sourceMappingURL=debug-id-upload.js.map
|