dtsroll 1.7.2 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { cli } from 'cleye';
3
- import { b as bgYellow, a as black, d as dtsroll, l as logOutput, D as DtsrollBuildError } from './index-DaiC_aHH.mjs';
3
+ import { b as bgYellow, a as black, d as dtsroll, l as logOutput, D as DtsrollBuildError } from './index-J5sfIUfU.mjs';
4
4
  import 'node:path';
5
5
  import 'node:fs/promises';
6
6
  import 'rollup';
@@ -13,7 +13,7 @@ import 'resolve-pkg-maps';
13
13
  import 'byte-size';
14
14
 
15
15
  var name = "dtsroll";
16
- var version = "1.7.2";
16
+ var version = "1.7.3";
17
17
  var description = "Bundle dts files";
18
18
 
19
19
  const argv = cli({
@@ -3937,8 +3937,8 @@ function hydrateSourcemap(sparseMappings, inputMap, outputCode) {
3937
3937
  hydratedMappings.push([]);
3938
3938
  continue;
3939
3939
  }
3940
- const anchor = sparseSegments[0];
3941
- if (!anchor || anchor.length < 4) {
3940
+ const anchor = sparseSegments.find((segment) => segment.length >= 4);
3941
+ if (!anchor) {
3942
3942
  hydratedMappings.push(sparseSegments);
3943
3943
  continue;
3944
3944
  }
@@ -4114,13 +4114,34 @@ const transform = () => {
4114
4114
  fileName,
4115
4115
  inputMap: await loadInputSourcemap(info)
4116
4116
  })));
4117
+ const isUrl = (p) => /^[a-z][a-z0-9+.-]*:\/\//i.test(p);
4117
4118
  for (const { fileName, inputMap } of loadedMaps) {
4118
4119
  if (inputMap && inputMap.sources) {
4119
4120
  const inputMapDir = path.dirname(fileName);
4121
+ let sourceRoot;
4122
+ if (inputMap.sourceRoot) {
4123
+ sourceRoot = isUrl(inputMap.sourceRoot) ? inputMap.sourceRoot : path.resolve(inputMapDir, inputMap.sourceRoot);
4124
+ } else {
4125
+ sourceRoot = inputMapDir;
4126
+ }
4127
+ const sourceRootIsUrl = isUrl(sourceRoot);
4120
4128
  inputSourcemaps.set(fileName, {
4121
4129
  version: inputMap.version ?? 3,
4122
- sources: inputMap.sources.map((source) => path.isAbsolute(source) ? source : path.resolve(inputMapDir, source)),
4123
- sourcesContent: inputMap.sourcesContent,
4130
+ sources: inputMap.sources.map((source) => {
4131
+ if (source === null)
4132
+ return null;
4133
+ if (isUrl(source))
4134
+ return source;
4135
+ if (sourceRootIsUrl) {
4136
+ const base = sourceRoot.endsWith("/") ? sourceRoot : sourceRoot + "/";
4137
+ return new URL(source, base).toString();
4138
+ }
4139
+ return path.isAbsolute(source) ? source : path.resolve(sourceRoot, source);
4140
+ }),
4141
+ // Note: sourcesContent intentionally not copied.
4142
+ // TypeScript's declaration maps never include sourcesContent, and tsserver's
4143
+ // getDocumentPositionMapper() rejects maps that have it (returns identity mapper).
4144
+ // https://github.com/microsoft/TypeScript/blob/b19a9da2a3b8f2a720d314d01258dd2bdc110fef/src/services/sourcemaps.ts#L226
4124
4145
  mappings: inputMap.mappings,
4125
4146
  names: inputMap.names
4126
4147
  });
@@ -4132,13 +4153,18 @@ const transform = () => {
4132
4153
  continue;
4133
4154
  const chunkDir = path.join(outputDir, path.dirname(chunk.fileName));
4134
4155
  const toRelativeSourcePath = (source) => {
4156
+ if (isUrl(source))
4157
+ return source;
4135
4158
  const relative = path.isAbsolute(source) ? path.relative(chunkDir, source) : source;
4136
4159
  return relative.replaceAll("\\", "/");
4137
4160
  };
4161
+ const toRelativeSourcePathOrNull = (source) => source === null ? null : toRelativeSourcePath(source);
4138
4162
  const sourcesToRemap = /* @__PURE__ */ new Map();
4139
4163
  for (const source of chunk.map.sources) {
4140
4164
  if (!source)
4141
4165
  continue;
4166
+ if (isUrl(source))
4167
+ continue;
4142
4168
  const absoluteSource = path.resolve(chunkDir, source);
4143
4169
  const inputMap = inputSourcemaps.get(absoluteSource);
4144
4170
  if (inputMap) {
@@ -4149,13 +4175,11 @@ const transform = () => {
4149
4175
  if (chunk.map.sources.length === 0 && chunk.facadeModuleId) {
4150
4176
  const inputMap = inputSourcemaps.get(chunk.facadeModuleId);
4151
4177
  if (inputMap && inputMap.sources.length > 0) {
4152
- const newSources2 = inputMap.sources.map(toRelativeSourcePath);
4153
- const newSourcesContent2 = inputMap.sourcesContent || [];
4178
+ const newSources2 = inputMap.sources.map(toRelativeSourcePathOrNull);
4154
4179
  chunk.map.sources = newSources2;
4155
- chunk.map.sourcesContent = newSourcesContent2;
4180
+ delete chunk.map.sourcesContent;
4156
4181
  updateSourcemapAsset(bundle, chunk.fileName, {
4157
4182
  sources: newSources2,
4158
- sourcesContent: newSourcesContent2,
4159
4183
  mappings: chunk.map.mappings,
4160
4184
  names: chunk.map.names || []
4161
4185
  });
@@ -4167,12 +4191,10 @@ const transform = () => {
4167
4191
  const singleInputMap = isSingleSource ? Array.from(sourcesToRemap.values())[0] : null;
4168
4192
  const canSimplyReplace = singleInputMap && singleInputMap.sources.length === 1;
4169
4193
  let newSources;
4170
- let newSourcesContent;
4171
4194
  let newMappings;
4172
4195
  let newNames;
4173
4196
  if (canSimplyReplace && singleInputMap) {
4174
- newSources = singleInputMap.sources.map(toRelativeSourcePath);
4175
- newSourcesContent = singleInputMap.sourcesContent || [null];
4197
+ newSources = singleInputMap.sources.map(toRelativeSourcePathOrNull);
4176
4198
  newMappings = hydrateSourcemap(chunk.map.mappings, singleInputMap, chunk.code);
4177
4199
  newNames = singleInputMap.names || [];
4178
4200
  } else {
@@ -4184,18 +4206,16 @@ const transform = () => {
4184
4206
  }
4185
4207
  return null;
4186
4208
  });
4187
- newSources = remapped.sources.filter((s) => s !== null).map(toRelativeSourcePath);
4188
- newSourcesContent = remapped.sourcesContent || [];
4209
+ newSources = remapped.sources.map(toRelativeSourcePathOrNull);
4189
4210
  newMappings = typeof remapped.mappings === "string" ? remapped.mappings : "";
4190
4211
  newNames = remapped.names || [];
4191
4212
  }
4192
4213
  chunk.map.sources = newSources;
4193
- chunk.map.sourcesContent = newSourcesContent;
4214
+ delete chunk.map.sourcesContent;
4194
4215
  chunk.map.mappings = newMappings;
4195
4216
  chunk.map.names = newNames;
4196
4217
  updateSourcemapAsset(bundle, chunk.fileName, {
4197
4218
  sources: newSources,
4198
- sourcesContent: newSourcesContent,
4199
4219
  mappings: newMappings,
4200
4220
  names: newNames
4201
4221
  });
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import 'node:path';
3
- export { d as dtsroll } from './index-DaiC_aHH.mjs';
3
+ export { d as dtsroll } from './index-J5sfIUfU.mjs';
4
4
  import 'node:fs/promises';
5
5
  import 'rollup';
6
6
  import 'typescript';
package/dist/vite.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { d as dtsroll, l as logOutput } from './index-DaiC_aHH.mjs';
2
+ import { d as dtsroll, l as logOutput } from './index-J5sfIUfU.mjs';
3
3
  import 'node:path';
4
4
  import 'node:fs/promises';
5
5
  import 'rollup';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dtsroll",
3
- "version": "1.7.2",
3
+ "version": "1.7.3",
4
4
  "description": "Bundle dts files",
5
5
  "keywords": [
6
6
  "bundle",