@cedarjs/vite 6.0.0-canary.2696 → 6.0.0-canary.2697

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 +1 @@
1
- {"version":3,"file":"apiDevMiddleware.d.ts","sourceRoot":"","sources":["../src/apiDevMiddleware.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAsB,aAAa,EAAE,MAAM,MAAM,CAAA;AAgE7D,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,aAAa,iBAe/D;AA+GD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC,CA8IlE;AA0BD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI,CA0EhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,KAIrB,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAoFnD;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,UAAU,EAAE,aAAa,CAAA;IACzB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CACjD,CAAC,CAcD"}
1
+ {"version":3,"file":"apiDevMiddleware.d.ts","sourceRoot":"","sources":["../src/apiDevMiddleware.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAsB,aAAa,EAAE,MAAM,MAAM,CAAA;AAkE7D,wBAAsB,gBAAgB,CAAC,UAAU,EAAE,aAAa,iBAe/D;AA+GD,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,aAAa,CAAC,CAoMlE;AA0BD,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,aAAa,GAAG,IAAI,CA0EhE;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,KAIrB,SAAS,OAAO,KAAG,OAAO,CAAC,QAAQ,CAAC,CAoFnD;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC;IACrD,UAAU,EAAE,aAAa,CAAA;IACzB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC1B,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CACjD,CAAC,CAcD"}
@@ -13,13 +13,15 @@ const tsconfigPaths = (
13
13
  );
14
14
  import { buildCedarContext, wrapLegacyHandler } from "@cedarjs/api/runtime";
15
15
  import {
16
- getApiSideBabelPlugins,
16
+ getApiSideBabelConfigPath,
17
+ getApiSideBabelPluginsForVite,
17
18
  transformWithBabel
18
19
  } from "@cedarjs/babel-config";
19
20
  import { getAsyncStoreInstance } from "@cedarjs/context/dist/store";
20
21
  import { createGraphQLYoga } from "@cedarjs/graphql-server";
21
22
  import { applyGqlormInject } from "@cedarjs/internal/dist/build/api-graphql-transforms.js";
22
- import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
23
+ import { getConfig, getPaths } from "@cedarjs/project-config";
24
+ import { generateDiffSourceMap } from "./lib/generateDiffSourceMap.js";
23
25
  import { getWorkspacePackageAliases } from "./lib/workspacePackageAliases.js";
24
26
  import { cedarAutoImportsPlugin } from "./plugins/vite-plugin-cedar-auto-import.js";
25
27
  import { cedarDirectoryNamedImportPlugin } from "./plugins/vite-plugin-cedar-directory-named-import.js";
@@ -143,12 +145,8 @@ async function internalLoadApiFunctions(viteServer) {
143
145
  async function createApiViteServer() {
144
146
  const cedarPaths = getPaths();
145
147
  const cedarConfig = getConfig();
146
- const isEsm = projectSideIsEsm("api");
147
148
  const normalizedBase = normalizePath(cedarPaths.base);
148
- const babelPlugins = getApiSideBabelPlugins({
149
- forVite: true,
150
- projectIsEsm: isEsm
151
- });
149
+ const babelPlugins = getApiSideBabelConfigPath() ? getApiSideBabelPluginsForVite() : null;
152
150
  const workspacePkgSourceMap = Object.fromEntries(
153
151
  Object.entries(getWorkspacePackageAliases(cedarPaths, cedarConfig)).map(
154
152
  ([name, sourceFile]) => [name, normalizePath(sourceFile)]
@@ -213,24 +211,50 @@ async function createApiViteServer() {
213
211
  }
214
212
  try {
215
213
  let sourceCode = code;
214
+ let sourceMap = null;
216
215
  if (normalizePath(id).endsWith("/graphql.ts") || normalizePath(id).endsWith("/graphql.js")) {
217
216
  const extracted = applyGraphqlOptionsExtract(sourceCode);
218
- sourceCode = extracted?.code ?? sourceCode;
219
- sourceCode = applyGqlormInject(sourceCode, id) ?? sourceCode;
217
+ if (extracted) {
218
+ sourceCode = extracted.code;
219
+ sourceMap = extracted.map;
220
+ }
221
+ const injected = applyGqlormInject(sourceCode, id);
222
+ if (injected) {
223
+ sourceCode = injected;
224
+ sourceMap = null;
225
+ }
220
226
  }
221
227
  if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
222
228
  const relativePath = normalizePath(id).slice(
223
229
  normalizedBase.length + "/api/src/".length
224
230
  );
225
231
  const apiFolder = relativePath.split("/")[0] ?? "?";
226
- sourceCode = applyOtelWrapping(sourceCode, id, apiFolder) ?? sourceCode;
232
+ const wrapped = applyOtelWrapping(sourceCode, id, apiFolder);
233
+ if (wrapped) {
234
+ sourceCode = wrapped;
235
+ sourceMap = null;
236
+ }
237
+ }
238
+ if (!babelPlugins) {
239
+ if (sourceCode === code) {
240
+ return null;
241
+ }
242
+ return {
243
+ code: sourceCode,
244
+ map: sourceMap ?? generateDiffSourceMap(code, sourceCode)
245
+ };
246
+ }
247
+ const inputSourceMap = sourceCode === code ? null : sourceMap ?? generateDiffSourceMap(code, sourceCode);
248
+ if (inputSourceMap) {
249
+ inputSourceMap.sources = [id];
227
250
  }
228
251
  const result = await transformWithBabel(
229
252
  sourceCode,
230
253
  id,
231
254
  babelPlugins,
232
255
  true,
233
- true
256
+ true,
257
+ inputSourceMap ?? void 0
234
258
  );
235
259
  if (!result?.code) {
236
260
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"buildApp.d.ts","sourceRoot":"","sources":["../src/buildApp.ts"],"names":[],"mappings":"AA2DA,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,EAAE,CAAC,EAAE,OAAO,CAAA;CACb;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAe,EACf,SAA0B,EAC1B,EAAU,GACX,GAAE,oBAAyB,iBA6X3B"}
1
+ {"version":3,"file":"buildApp.d.ts","sourceRoot":"","sources":["../src/buildApp.ts"],"names":[],"mappings":"AA6DA,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB,EAAE,CAAC,EAAE,OAAO,CAAA;CACb;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,EAClC,OAAe,EACf,SAA0B,EAC1B,EAAU,GACX,GAAE,oBAAyB,iBAya3B"}
package/dist/buildApp.js CHANGED
@@ -11,7 +11,8 @@ const tsconfigPaths = (
11
11
  tsPathsMod.default?.default || tsPathsMod.default || tsPathsMod
12
12
  );
13
13
  import {
14
- getApiSideBabelPlugins,
14
+ getApiSideBabelConfigPath,
15
+ getApiSideBabelPluginsForVite,
15
16
  transformWithBabel
16
17
  } from "@cedarjs/babel-config";
17
18
  import {
@@ -20,6 +21,7 @@ import {
20
21
  } from "@cedarjs/internal/dist/build/api.js";
21
22
  import { findApiFiles } from "@cedarjs/internal/dist/files.js";
22
23
  import { getConfig, getPaths, projectSideIsEsm } from "@cedarjs/project-config";
24
+ import { generateDiffSourceMap } from "./lib/generateDiffSourceMap.js";
23
25
  import { getWorkspacePackageAliases } from "./lib/workspacePackageAliases.js";
24
26
  import { cedarAutoImportsPlugin } from "./plugins/vite-plugin-cedar-auto-import.js";
25
27
  import { cedarDirectoryNamedImportPlugin } from "./plugins/vite-plugin-cedar-directory-named-import.js";
@@ -118,10 +120,6 @@ async function buildCedarApp({
118
120
  };
119
121
  }
120
122
  }
121
- const babelPlugins = workspace.includes("api") ? getApiSideBabelPlugins({
122
- forVite: true,
123
- projectIsEsm: projectSideIsEsm("api")
124
- }) : null;
125
123
  const workspacePkgSourceMap = workspace.includes("api") ? Object.fromEntries(
126
124
  Object.entries(getWorkspacePackageAliases(cedarPaths, cedarConfig)).map(
127
125
  ([name, sourceFile]) => [name, normalizePath(sourceFile)]
@@ -263,7 +261,7 @@ async function buildCedarApp({
263
261
  );
264
262
  }
265
263
  plugins.push(cedarMockCellDataPlugin());
266
- if (babelPlugins) {
264
+ if (workspace.includes("api")) {
267
265
  plugins.push({
268
266
  name: "cedar-vite-api-babel-transform",
269
267
  enforce: "pre",
@@ -277,31 +275,47 @@ async function buildCedarApp({
277
275
  if (!normalizePath(id).startsWith(normalizePath(cedarPaths.api.base))) {
278
276
  return null;
279
277
  }
280
- const transformedCode = await transformWithBabel(
281
- code,
282
- id,
283
- babelPlugins,
284
- true,
285
- true
278
+ const babelPlugins = getApiSideBabelConfigPath() ? getApiSideBabelPluginsForVite() : null;
279
+ const fromDirRelativeToApiSrc = path.relative(
280
+ cedarPaths.api.src,
281
+ path.dirname(id)
286
282
  );
287
- if (transformedCode?.code) {
288
- const fromDirRelativeToApiSrc = path.relative(
289
- cedarPaths.api.src,
290
- path.dirname(id)
291
- );
292
- let outputCode = applySrcAlias(
293
- transformedCode.code,
294
- fromDirRelativeToApiSrc
295
- );
283
+ const applyImportRewrites = (source) => {
284
+ let rewritten = applySrcAlias(source, fromDirRelativeToApiSrc);
296
285
  if (projectSideIsEsm("api")) {
297
- outputCode = applyEsmExtensions(outputCode, id);
286
+ rewritten = applyEsmExtensions(rewritten, id);
287
+ }
288
+ return rewritten;
289
+ };
290
+ const rewrittenCode = applyImportRewrites(code);
291
+ if (!babelPlugins) {
292
+ if (rewrittenCode === code) {
293
+ return null;
298
294
  }
299
295
  return {
300
- code: outputCode,
301
- map: transformedCode.map ?? null
296
+ code: rewrittenCode,
297
+ map: generateDiffSourceMap(code, rewrittenCode)
302
298
  };
303
299
  }
304
- return null;
300
+ const inputSourceMap = rewrittenCode === code ? null : generateDiffSourceMap(code, rewrittenCode);
301
+ if (inputSourceMap) {
302
+ inputSourceMap.sources = [id];
303
+ }
304
+ const transformedCode = await transformWithBabel(
305
+ rewrittenCode,
306
+ id,
307
+ babelPlugins,
308
+ true,
309
+ true,
310
+ inputSourceMap ?? void 0
311
+ );
312
+ if (!transformedCode?.code) {
313
+ return null;
314
+ }
315
+ return {
316
+ code: applyImportRewrites(transformedCode.code),
317
+ map: transformedCode.map ?? null
318
+ };
305
319
  }
306
320
  });
307
321
  }
@@ -49,6 +49,7 @@ var import_store = require("@cedarjs/context/dist/store");
49
49
  var import_graphql_server = require("@cedarjs/graphql-server");
50
50
  var import_api_graphql_transforms = require("@cedarjs/internal/dist/build/api-graphql-transforms.js");
51
51
  var import_project_config = require("@cedarjs/project-config");
52
+ var import_generateDiffSourceMap = require("./lib/generateDiffSourceMap.js");
52
53
  var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
53
54
  var import_vite_plugin_cedar_auto_import = require("./plugins/vite-plugin-cedar-auto-import.js");
54
55
  var import_vite_plugin_cedar_directory_named_import = require("./plugins/vite-plugin-cedar-directory-named-import.js");
@@ -177,12 +178,8 @@ async function internalLoadApiFunctions(viteServer) {
177
178
  async function createApiViteServer() {
178
179
  const cedarPaths = (0, import_project_config.getPaths)();
179
180
  const cedarConfig = (0, import_project_config.getConfig)();
180
- const isEsm = (0, import_project_config.projectSideIsEsm)("api");
181
181
  const normalizedBase = (0, import_vite.normalizePath)(cedarPaths.base);
182
- const babelPlugins = (0, import_babel_config.getApiSideBabelPlugins)({
183
- forVite: true,
184
- projectIsEsm: isEsm
185
- });
182
+ const babelPlugins = (0, import_babel_config.getApiSideBabelConfigPath)() ? (0, import_babel_config.getApiSideBabelPluginsForVite)() : null;
186
183
  const workspacePkgSourceMap = Object.fromEntries(
187
184
  Object.entries((0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig)).map(
188
185
  ([name, sourceFile]) => [name, (0, import_vite.normalizePath)(sourceFile)]
@@ -247,24 +244,50 @@ async function createApiViteServer() {
247
244
  }
248
245
  try {
249
246
  let sourceCode = code;
247
+ let sourceMap = null;
250
248
  if ((0, import_vite.normalizePath)(id).endsWith("/graphql.ts") || (0, import_vite.normalizePath)(id).endsWith("/graphql.js")) {
251
249
  const extracted = (0, import_vite_plugin_cedar_graphql_options_extract.applyGraphqlOptionsExtract)(sourceCode);
252
- sourceCode = extracted?.code ?? sourceCode;
253
- sourceCode = (0, import_api_graphql_transforms.applyGqlormInject)(sourceCode, id) ?? sourceCode;
250
+ if (extracted) {
251
+ sourceCode = extracted.code;
252
+ sourceMap = extracted.map;
253
+ }
254
+ const injected = (0, import_api_graphql_transforms.applyGqlormInject)(sourceCode, id);
255
+ if (injected) {
256
+ sourceCode = injected;
257
+ sourceMap = null;
258
+ }
254
259
  }
255
260
  if (cedarConfig.experimental?.opentelemetry?.enabled && cedarConfig.experimental?.opentelemetry?.wrapApi) {
256
261
  const relativePath = (0, import_vite.normalizePath)(id).slice(
257
262
  normalizedBase.length + "/api/src/".length
258
263
  );
259
264
  const apiFolder = relativePath.split("/")[0] ?? "?";
260
- sourceCode = (0, import_vite_plugin_cedar_otel_wrapping.applyOtelWrapping)(sourceCode, id, apiFolder) ?? sourceCode;
265
+ const wrapped = (0, import_vite_plugin_cedar_otel_wrapping.applyOtelWrapping)(sourceCode, id, apiFolder);
266
+ if (wrapped) {
267
+ sourceCode = wrapped;
268
+ sourceMap = null;
269
+ }
270
+ }
271
+ if (!babelPlugins) {
272
+ if (sourceCode === code) {
273
+ return null;
274
+ }
275
+ return {
276
+ code: sourceCode,
277
+ map: sourceMap ?? (0, import_generateDiffSourceMap.generateDiffSourceMap)(code, sourceCode)
278
+ };
279
+ }
280
+ const inputSourceMap = sourceCode === code ? null : sourceMap ?? (0, import_generateDiffSourceMap.generateDiffSourceMap)(code, sourceCode);
281
+ if (inputSourceMap) {
282
+ inputSourceMap.sources = [id];
261
283
  }
262
284
  const result = await (0, import_babel_config.transformWithBabel)(
263
285
  sourceCode,
264
286
  id,
265
287
  babelPlugins,
266
288
  true,
267
- true
289
+ true,
290
+ inputSourceMap ?? void 0
268
291
  );
269
292
  if (!result?.code) {
270
293
  return null;
@@ -42,6 +42,7 @@ var import_babel_config = require("@cedarjs/babel-config");
42
42
  var import_api = require("@cedarjs/internal/dist/build/api.js");
43
43
  var import_files = require("@cedarjs/internal/dist/files.js");
44
44
  var import_project_config = require("@cedarjs/project-config");
45
+ var import_generateDiffSourceMap = require("./lib/generateDiffSourceMap.js");
45
46
  var import_workspacePackageAliases = require("./lib/workspacePackageAliases.js");
46
47
  var import_vite_plugin_cedar_auto_import = require("./plugins/vite-plugin-cedar-auto-import.js");
47
48
  var import_vite_plugin_cedar_directory_named_import = require("./plugins/vite-plugin-cedar-directory-named-import.js");
@@ -145,10 +146,6 @@ async function buildCedarApp({
145
146
  };
146
147
  }
147
148
  }
148
- const babelPlugins = workspace.includes("api") ? (0, import_babel_config.getApiSideBabelPlugins)({
149
- forVite: true,
150
- projectIsEsm: (0, import_project_config.projectSideIsEsm)("api")
151
- }) : null;
152
149
  const workspacePkgSourceMap = workspace.includes("api") ? Object.fromEntries(
153
150
  Object.entries((0, import_workspacePackageAliases.getWorkspacePackageAliases)(cedarPaths, cedarConfig)).map(
154
151
  ([name, sourceFile]) => [name, (0, import_vite2.normalizePath)(sourceFile)]
@@ -290,7 +287,7 @@ async function buildCedarApp({
290
287
  );
291
288
  }
292
289
  plugins.push((0, import_vite_plugin_cedar_mock_cell_data.cedarMockCellDataPlugin)());
293
- if (babelPlugins) {
290
+ if (workspace.includes("api")) {
294
291
  plugins.push({
295
292
  name: "cedar-vite-api-babel-transform",
296
293
  enforce: "pre",
@@ -304,31 +301,47 @@ async function buildCedarApp({
304
301
  if (!(0, import_vite2.normalizePath)(id).startsWith((0, import_vite2.normalizePath)(cedarPaths.api.base))) {
305
302
  return null;
306
303
  }
307
- const transformedCode = await (0, import_babel_config.transformWithBabel)(
308
- code,
309
- id,
310
- babelPlugins,
311
- true,
312
- true
304
+ const babelPlugins = (0, import_babel_config.getApiSideBabelConfigPath)() ? (0, import_babel_config.getApiSideBabelPluginsForVite)() : null;
305
+ const fromDirRelativeToApiSrc = import_node_path.default.relative(
306
+ cedarPaths.api.src,
307
+ import_node_path.default.dirname(id)
313
308
  );
314
- if (transformedCode?.code) {
315
- const fromDirRelativeToApiSrc = import_node_path.default.relative(
316
- cedarPaths.api.src,
317
- import_node_path.default.dirname(id)
318
- );
319
- let outputCode = (0, import_api.applySrcAlias)(
320
- transformedCode.code,
321
- fromDirRelativeToApiSrc
322
- );
309
+ const applyImportRewrites = (source) => {
310
+ let rewritten = (0, import_api.applySrcAlias)(source, fromDirRelativeToApiSrc);
323
311
  if ((0, import_project_config.projectSideIsEsm)("api")) {
324
- outputCode = (0, import_api.applyEsmExtensions)(outputCode, id);
312
+ rewritten = (0, import_api.applyEsmExtensions)(rewritten, id);
313
+ }
314
+ return rewritten;
315
+ };
316
+ const rewrittenCode = applyImportRewrites(code);
317
+ if (!babelPlugins) {
318
+ if (rewrittenCode === code) {
319
+ return null;
325
320
  }
326
321
  return {
327
- code: outputCode,
328
- map: transformedCode.map ?? null
322
+ code: rewrittenCode,
323
+ map: (0, import_generateDiffSourceMap.generateDiffSourceMap)(code, rewrittenCode)
329
324
  };
330
325
  }
331
- return null;
326
+ const inputSourceMap = rewrittenCode === code ? null : (0, import_generateDiffSourceMap.generateDiffSourceMap)(code, rewrittenCode);
327
+ if (inputSourceMap) {
328
+ inputSourceMap.sources = [id];
329
+ }
330
+ const transformedCode = await (0, import_babel_config.transformWithBabel)(
331
+ rewrittenCode,
332
+ id,
333
+ babelPlugins,
334
+ true,
335
+ true,
336
+ inputSourceMap ?? void 0
337
+ );
338
+ if (!transformedCode?.code) {
339
+ return null;
340
+ }
341
+ return {
342
+ code: applyImportRewrites(transformedCode.code),
343
+ map: transformedCode.map ?? null
344
+ };
332
345
  }
333
346
  });
334
347
  }
@@ -0,0 +1,185 @@
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
+ var generateDiffSourceMap_exports = {};
30
+ __export(generateDiffSourceMap_exports, {
31
+ generateDiffSourceMap: () => generateDiffSourceMap
32
+ });
33
+ module.exports = __toCommonJS(generateDiffSourceMap_exports);
34
+ var import_magic_string = __toESM(require("magic-string"), 1);
35
+ const MAX_ALIGNMENT_CELLS = 1e6;
36
+ function generateDiffSourceMap(original, transformed) {
37
+ if (original === transformed) {
38
+ return null;
39
+ }
40
+ const ms = new import_magic_string.default(original);
41
+ const origLines = original.split("\n");
42
+ const newLines = transformed.split("\n");
43
+ const lineOffsets = new Array(origLines.length);
44
+ let offset = 0;
45
+ for (let i = 0; i < origLines.length; i++) {
46
+ lineOffsets[i] = offset;
47
+ offset += origLines[i].length + 1;
48
+ }
49
+ let prefix = 0;
50
+ const maxPrefix = Math.min(origLines.length, newLines.length);
51
+ while (prefix < maxPrefix && origLines[prefix] === newLines[prefix]) {
52
+ prefix++;
53
+ }
54
+ let suffix = 0;
55
+ const maxSuffix = Math.min(origLines.length, newLines.length) - prefix;
56
+ while (suffix < maxSuffix && origLines[origLines.length - 1 - suffix] === newLines[newLines.length - 1 - suffix]) {
57
+ suffix++;
58
+ }
59
+ const hunks = alignLines(
60
+ origLines,
61
+ prefix,
62
+ origLines.length - suffix,
63
+ newLines,
64
+ prefix,
65
+ newLines.length - suffix
66
+ );
67
+ for (const hunk of hunks) {
68
+ applyHunk(ms, hunk, origLines, newLines, lineOffsets, original.length);
69
+ }
70
+ if (ms.toString() !== transformed) {
71
+ return new import_magic_string.default(original).generateMap({ hires: true });
72
+ }
73
+ return ms.generateMap({ hires: true });
74
+ }
75
+ function alignLines(origLines, oLo, oHi, newLines, nLo, nHi) {
76
+ const m = oHi - oLo;
77
+ const n = nHi - nLo;
78
+ if (m === 0 && n === 0) {
79
+ return [];
80
+ }
81
+ if (m === 0 || n === 0 || m * n > MAX_ALIGNMENT_CELLS) {
82
+ return [{ oStart: oLo, oEnd: oHi, nStart: nLo, nEnd: nHi }];
83
+ }
84
+ const width = n + 1;
85
+ const dp = new Int32Array((m + 1) * width);
86
+ for (let i2 = m - 1; i2 >= 0; i2--) {
87
+ for (let j2 = n - 1; j2 >= 0; j2--) {
88
+ dp[i2 * width + j2] = origLines[oLo + i2] === newLines[nLo + j2] ? dp[(i2 + 1) * width + j2 + 1] + 1 : Math.max(dp[(i2 + 1) * width + j2], dp[i2 * width + j2 + 1]);
89
+ }
90
+ }
91
+ const hunks = [];
92
+ let i = 0;
93
+ let j = 0;
94
+ let hunkO = 0;
95
+ let hunkN = 0;
96
+ const flushHunk = () => {
97
+ if (i > hunkO || j > hunkN) {
98
+ hunks.push({
99
+ oStart: oLo + hunkO,
100
+ oEnd: oLo + i,
101
+ nStart: nLo + hunkN,
102
+ nEnd: nLo + j
103
+ });
104
+ }
105
+ };
106
+ while (i < m && j < n) {
107
+ if (origLines[oLo + i] === newLines[nLo + j]) {
108
+ flushHunk();
109
+ i++;
110
+ j++;
111
+ hunkO = i;
112
+ hunkN = j;
113
+ } else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
114
+ i++;
115
+ } else {
116
+ j++;
117
+ }
118
+ }
119
+ i = m;
120
+ j = n;
121
+ flushHunk();
122
+ return hunks;
123
+ }
124
+ function applyHunk(ms, { oStart, oEnd, nStart, nEnd }, origLines, newLines, lineOffsets, originalLength) {
125
+ const oCount = oEnd - oStart;
126
+ const nCount = nEnd - nStart;
127
+ const newSlice = newLines.slice(nStart, nEnd);
128
+ if (oCount === nCount) {
129
+ for (let k = 0; k < oCount; k++) {
130
+ diffLinePair(
131
+ ms,
132
+ lineOffsets[oStart + k],
133
+ origLines[oStart + k],
134
+ newLines[nStart + k]
135
+ );
136
+ }
137
+ } else if (oCount === 0) {
138
+ const text = newSlice.join("\n");
139
+ if (oStart >= origLines.length) {
140
+ ms.appendLeft(originalLength, "\n" + text);
141
+ } else {
142
+ ms.appendLeft(lineOffsets[oStart], text + "\n");
143
+ }
144
+ } else if (nCount === 0) {
145
+ const start = lineOffsets[oStart];
146
+ if (oEnd >= origLines.length) {
147
+ ms.remove(oStart > 0 ? start - 1 : start, originalLength);
148
+ } else {
149
+ ms.remove(start, lineOffsets[oEnd]);
150
+ }
151
+ } else {
152
+ const start = lineOffsets[oStart];
153
+ const end = lineOffsets[oEnd - 1] + origLines[oEnd - 1].length;
154
+ ms.overwrite(start, end, newSlice.join("\n"));
155
+ }
156
+ }
157
+ function diffLinePair(ms, lineStart, origLine, newLine) {
158
+ if (origLine === newLine) {
159
+ return;
160
+ }
161
+ let charPrefix = 0;
162
+ const maxCharPrefix = Math.min(origLine.length, newLine.length);
163
+ while (charPrefix < maxCharPrefix && origLine[charPrefix] === newLine[charPrefix]) {
164
+ charPrefix++;
165
+ }
166
+ let charSuffix = 0;
167
+ const maxCharSuffix = Math.min(origLine.length, newLine.length) - charPrefix;
168
+ while (charSuffix < maxCharSuffix && origLine[origLine.length - 1 - charSuffix] === newLine[newLine.length - 1 - charSuffix]) {
169
+ charSuffix++;
170
+ }
171
+ const start = lineStart + charPrefix;
172
+ const end = lineStart + origLine.length - charSuffix;
173
+ const replacement = newLine.slice(charPrefix, newLine.length - charSuffix);
174
+ if (start === end) {
175
+ ms.appendLeft(start, replacement);
176
+ } else if (replacement === "") {
177
+ ms.remove(start, end);
178
+ } else {
179
+ ms.overwrite(start, end, replacement);
180
+ }
181
+ }
182
+ // Annotate the CommonJS export names for ESM import in node:
183
+ 0 && (module.exports = {
184
+ generateDiffSourceMap
185
+ });
@@ -0,0 +1,18 @@
1
+ import type { SourceMap } from 'magic-string';
2
+ /**
3
+ * Generates a sourcemap for a string transform by diffing its input and
4
+ * output. Used for transforms that don't produce a map themselves.
5
+ *
6
+ * The diff first anchors on the common prefix and suffix lines, then aligns
7
+ * the remaining lines with an LCS so that unchanged lines *inside* the
8
+ * changed region (e.g. statements inside a newly inserted wrapper) also map
9
+ * exactly. Aligned line pairs that differ are refined with a character-level
10
+ * prefix/suffix diff, which gives exact column mappings for in-place
11
+ * rewrites (e.g. import specifier rewrites) — including the columns after
12
+ * the rewritten span. Only lines with no counterpart at all map coarsely, to
13
+ * the start of their surrounding edit.
14
+ *
15
+ * Returns null when the input and output are identical.
16
+ */
17
+ export declare function generateDiffSourceMap(original: string, transformed: string): SourceMap | null;
18
+ //# sourceMappingURL=generateDiffSourceMap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateDiffSourceMap.d.ts","sourceRoot":"","sources":["../../src/lib/generateDiffSourceMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAc7C;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,SAAS,GAAG,IAAI,CA0DlB"}
@@ -0,0 +1,151 @@
1
+ import MagicString from "magic-string";
2
+ const MAX_ALIGNMENT_CELLS = 1e6;
3
+ function generateDiffSourceMap(original, transformed) {
4
+ if (original === transformed) {
5
+ return null;
6
+ }
7
+ const ms = new MagicString(original);
8
+ const origLines = original.split("\n");
9
+ const newLines = transformed.split("\n");
10
+ const lineOffsets = new Array(origLines.length);
11
+ let offset = 0;
12
+ for (let i = 0; i < origLines.length; i++) {
13
+ lineOffsets[i] = offset;
14
+ offset += origLines[i].length + 1;
15
+ }
16
+ let prefix = 0;
17
+ const maxPrefix = Math.min(origLines.length, newLines.length);
18
+ while (prefix < maxPrefix && origLines[prefix] === newLines[prefix]) {
19
+ prefix++;
20
+ }
21
+ let suffix = 0;
22
+ const maxSuffix = Math.min(origLines.length, newLines.length) - prefix;
23
+ while (suffix < maxSuffix && origLines[origLines.length - 1 - suffix] === newLines[newLines.length - 1 - suffix]) {
24
+ suffix++;
25
+ }
26
+ const hunks = alignLines(
27
+ origLines,
28
+ prefix,
29
+ origLines.length - suffix,
30
+ newLines,
31
+ prefix,
32
+ newLines.length - suffix
33
+ );
34
+ for (const hunk of hunks) {
35
+ applyHunk(ms, hunk, origLines, newLines, lineOffsets, original.length);
36
+ }
37
+ if (ms.toString() !== transformed) {
38
+ return new MagicString(original).generateMap({ hires: true });
39
+ }
40
+ return ms.generateMap({ hires: true });
41
+ }
42
+ function alignLines(origLines, oLo, oHi, newLines, nLo, nHi) {
43
+ const m = oHi - oLo;
44
+ const n = nHi - nLo;
45
+ if (m === 0 && n === 0) {
46
+ return [];
47
+ }
48
+ if (m === 0 || n === 0 || m * n > MAX_ALIGNMENT_CELLS) {
49
+ return [{ oStart: oLo, oEnd: oHi, nStart: nLo, nEnd: nHi }];
50
+ }
51
+ const width = n + 1;
52
+ const dp = new Int32Array((m + 1) * width);
53
+ for (let i2 = m - 1; i2 >= 0; i2--) {
54
+ for (let j2 = n - 1; j2 >= 0; j2--) {
55
+ dp[i2 * width + j2] = origLines[oLo + i2] === newLines[nLo + j2] ? dp[(i2 + 1) * width + j2 + 1] + 1 : Math.max(dp[(i2 + 1) * width + j2], dp[i2 * width + j2 + 1]);
56
+ }
57
+ }
58
+ const hunks = [];
59
+ let i = 0;
60
+ let j = 0;
61
+ let hunkO = 0;
62
+ let hunkN = 0;
63
+ const flushHunk = () => {
64
+ if (i > hunkO || j > hunkN) {
65
+ hunks.push({
66
+ oStart: oLo + hunkO,
67
+ oEnd: oLo + i,
68
+ nStart: nLo + hunkN,
69
+ nEnd: nLo + j
70
+ });
71
+ }
72
+ };
73
+ while (i < m && j < n) {
74
+ if (origLines[oLo + i] === newLines[nLo + j]) {
75
+ flushHunk();
76
+ i++;
77
+ j++;
78
+ hunkO = i;
79
+ hunkN = j;
80
+ } else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
81
+ i++;
82
+ } else {
83
+ j++;
84
+ }
85
+ }
86
+ i = m;
87
+ j = n;
88
+ flushHunk();
89
+ return hunks;
90
+ }
91
+ function applyHunk(ms, { oStart, oEnd, nStart, nEnd }, origLines, newLines, lineOffsets, originalLength) {
92
+ const oCount = oEnd - oStart;
93
+ const nCount = nEnd - nStart;
94
+ const newSlice = newLines.slice(nStart, nEnd);
95
+ if (oCount === nCount) {
96
+ for (let k = 0; k < oCount; k++) {
97
+ diffLinePair(
98
+ ms,
99
+ lineOffsets[oStart + k],
100
+ origLines[oStart + k],
101
+ newLines[nStart + k]
102
+ );
103
+ }
104
+ } else if (oCount === 0) {
105
+ const text = newSlice.join("\n");
106
+ if (oStart >= origLines.length) {
107
+ ms.appendLeft(originalLength, "\n" + text);
108
+ } else {
109
+ ms.appendLeft(lineOffsets[oStart], text + "\n");
110
+ }
111
+ } else if (nCount === 0) {
112
+ const start = lineOffsets[oStart];
113
+ if (oEnd >= origLines.length) {
114
+ ms.remove(oStart > 0 ? start - 1 : start, originalLength);
115
+ } else {
116
+ ms.remove(start, lineOffsets[oEnd]);
117
+ }
118
+ } else {
119
+ const start = lineOffsets[oStart];
120
+ const end = lineOffsets[oEnd - 1] + origLines[oEnd - 1].length;
121
+ ms.overwrite(start, end, newSlice.join("\n"));
122
+ }
123
+ }
124
+ function diffLinePair(ms, lineStart, origLine, newLine) {
125
+ if (origLine === newLine) {
126
+ return;
127
+ }
128
+ let charPrefix = 0;
129
+ const maxCharPrefix = Math.min(origLine.length, newLine.length);
130
+ while (charPrefix < maxCharPrefix && origLine[charPrefix] === newLine[charPrefix]) {
131
+ charPrefix++;
132
+ }
133
+ let charSuffix = 0;
134
+ const maxCharSuffix = Math.min(origLine.length, newLine.length) - charPrefix;
135
+ while (charSuffix < maxCharSuffix && origLine[origLine.length - 1 - charSuffix] === newLine[newLine.length - 1 - charSuffix]) {
136
+ charSuffix++;
137
+ }
138
+ const start = lineStart + charPrefix;
139
+ const end = lineStart + origLine.length - charSuffix;
140
+ const replacement = newLine.slice(charPrefix, newLine.length - charSuffix);
141
+ if (start === end) {
142
+ ms.appendLeft(start, replacement);
143
+ } else if (replacement === "") {
144
+ ms.remove(start, end);
145
+ } else {
146
+ ms.overwrite(start, end, replacement);
147
+ }
148
+ }
149
+ export {
150
+ generateDiffSourceMap
151
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/vite",
3
- "version": "6.0.0-canary.2696",
3
+ "version": "6.0.0-canary.2697",
4
4
  "description": "Vite configuration package for CedarJS",
5
5
  "repository": {
6
6
  "type": "git",
@@ -63,16 +63,16 @@
63
63
  "@babel/parser": "7.29.7",
64
64
  "@babel/traverse": "7.29.7",
65
65
  "@babel/types": "7.29.7",
66
- "@cedarjs/api": "6.0.0-canary.2696",
67
- "@cedarjs/api-server": "6.0.0-canary.2696",
68
- "@cedarjs/babel-config": "6.0.0-canary.2696",
69
- "@cedarjs/context": "6.0.0-canary.2696",
70
- "@cedarjs/cookie-jar": "6.0.0-canary.2696",
71
- "@cedarjs/graphql-server": "6.0.0-canary.2696",
72
- "@cedarjs/internal": "6.0.0-canary.2696",
73
- "@cedarjs/project-config": "6.0.0-canary.2696",
74
- "@cedarjs/server-store": "6.0.0-canary.2696",
75
- "@cedarjs/testing": "6.0.0-canary.2696",
66
+ "@cedarjs/api": "6.0.0-canary.2697",
67
+ "@cedarjs/api-server": "6.0.0-canary.2697",
68
+ "@cedarjs/babel-config": "6.0.0-canary.2697",
69
+ "@cedarjs/context": "6.0.0-canary.2697",
70
+ "@cedarjs/cookie-jar": "6.0.0-canary.2697",
71
+ "@cedarjs/graphql-server": "6.0.0-canary.2697",
72
+ "@cedarjs/internal": "6.0.0-canary.2697",
73
+ "@cedarjs/project-config": "6.0.0-canary.2697",
74
+ "@cedarjs/server-store": "6.0.0-canary.2697",
75
+ "@cedarjs/testing": "6.0.0-canary.2697",
76
76
  "@fastify/url-data": "6.0.3",
77
77
  "@swc/core": "1.15.41",
78
78
  "@universal-deploy/store": "^0.2.1",
@@ -109,9 +109,9 @@
109
109
  },
110
110
  "devDependencies": {
111
111
  "@arethetypeswrong/cli": "0.18.5",
112
- "@cedarjs/auth": "6.0.0-canary.2696",
113
- "@cedarjs/router": "6.0.0-canary.2696",
114
- "@cedarjs/web": "6.0.0-canary.2696",
112
+ "@cedarjs/auth": "6.0.0-canary.2697",
113
+ "@cedarjs/router": "6.0.0-canary.2697",
114
+ "@cedarjs/web": "6.0.0-canary.2697",
115
115
  "@hyrious/esbuild-plugin-commonjs": "0.2.6",
116
116
  "@jridgewell/trace-mapping": "0.3.31",
117
117
  "@types/aws-lambda": "8.10.162",
@@ -130,9 +130,9 @@
130
130
  "vitest": "4.1.10"
131
131
  },
132
132
  "peerDependencies": {
133
- "@cedarjs/auth": "6.0.0-canary.2696",
134
- "@cedarjs/router": "6.0.0-canary.2696",
135
- "@cedarjs/web": "6.0.0-canary.2696"
133
+ "@cedarjs/auth": "6.0.0-canary.2697",
134
+ "@cedarjs/router": "6.0.0-canary.2697",
135
+ "@cedarjs/web": "6.0.0-canary.2697"
136
136
  },
137
137
  "engines": {
138
138
  "node": ">=24"