@atlaspack/source-map 3.0.1-canary.4070
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/LICENSE +201 -0
- package/dist/SourceMap.js +377 -0
- package/dist/node.js +107 -0
- package/dist/types.js +2 -0
- package/dist/utils.js +59 -0
- package/lib/SourceMap.js +421 -0
- package/lib/node.js +92 -0
- package/lib/types/SourceMap.d.ts +229 -0
- package/lib/types/node.d.ts +17 -0
- package/lib/types/types.d.ts +44 -0
- package/lib/types/utils.d.ts +3 -0
- package/lib/types.js +1 -0
- package/lib/utils.js +69 -0
- package/package.json +27 -0
- package/src/SourceMap.ts +480 -0
- package/src/node.ts +116 -0
- package/src/types.ts +47 -0
- package/src/utils.ts +73 -0
- package/test/node.test.ts +30 -0
- package/tsconfig.json +12 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { ParsedMap, VLQMap, SourceMapStringifyOptions, IndexedMapping, GenerateEmptyMapOptions } from './types';
|
|
2
|
+
export declare const SOURCE_MAP_VERSION: string;
|
|
3
|
+
export default class SourceMap {
|
|
4
|
+
/**
|
|
5
|
+
* @private
|
|
6
|
+
*/
|
|
7
|
+
sourceMapInstance: any;
|
|
8
|
+
/**
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
projectRoot: string;
|
|
12
|
+
/**
|
|
13
|
+
* Construct a SourceMap instance
|
|
14
|
+
*
|
|
15
|
+
* @param projectRoot root directory of the project, this is to ensure all source paths are relative to this path
|
|
16
|
+
*/
|
|
17
|
+
constructor(projectRoot?: string, buffer?: Buffer);
|
|
18
|
+
get libraryVersion(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Generates an empty map from the provided fileName and sourceContent
|
|
21
|
+
*
|
|
22
|
+
* @param sourceName path of the source file
|
|
23
|
+
* @param sourceContent content of the source file
|
|
24
|
+
* @param lineOffset an offset that gets added to the sourceLine index of each mapping
|
|
25
|
+
*/
|
|
26
|
+
static generateEmptyMap({ projectRoot, sourceName, sourceContent, lineOffset, }: GenerateEmptyMapOptions): SourceMap;
|
|
27
|
+
/**
|
|
28
|
+
* Generates an empty map from the provided fileName and sourceContent
|
|
29
|
+
*
|
|
30
|
+
* @param sourceName path of the source file
|
|
31
|
+
* @param sourceContent content of the source file
|
|
32
|
+
* @param lineOffset an offset that gets added to the sourceLine index of each mapping
|
|
33
|
+
*/
|
|
34
|
+
addEmptyMap(sourceName: string, sourceContent: string, lineOffset?: number): SourceMap;
|
|
35
|
+
/**
|
|
36
|
+
* Appends raw VLQ mappings to the sourcemaps
|
|
37
|
+
*/
|
|
38
|
+
addVLQMap(map: VLQMap, lineOffset?: number, columnOffset?: number): SourceMap;
|
|
39
|
+
/**
|
|
40
|
+
* Appends another sourcemap instance to this sourcemap
|
|
41
|
+
*
|
|
42
|
+
* @param buffer the sourcemap buffer that should get appended to this sourcemap
|
|
43
|
+
* @param lineOffset an offset that gets added to the sourceLine index of each mapping
|
|
44
|
+
*/
|
|
45
|
+
addSourceMap(sourcemap: SourceMap, lineOffset?: number): SourceMap;
|
|
46
|
+
/**
|
|
47
|
+
* Appends a buffer to this sourcemap
|
|
48
|
+
* Note: The buffer should be generated by this library
|
|
49
|
+
* @param buffer the sourcemap buffer that should get appended to this sourcemap
|
|
50
|
+
* @param lineOffset an offset that gets added to the sourceLine index of each mapping
|
|
51
|
+
*/
|
|
52
|
+
addBuffer(buffer: Buffer, lineOffset?: number): SourceMap;
|
|
53
|
+
/**
|
|
54
|
+
* Appends a Mapping object to this sourcemap
|
|
55
|
+
* Note: line numbers start at 1 due to mozilla's source-map library
|
|
56
|
+
*
|
|
57
|
+
* @param mapping the mapping that should be appended to this sourcemap
|
|
58
|
+
* @param lineOffset an offset that gets added to the sourceLine index of each mapping
|
|
59
|
+
* @param columnOffset an offset that gets added to the sourceColumn index of each mapping
|
|
60
|
+
*/
|
|
61
|
+
addIndexedMapping(mapping: IndexedMapping<string>, lineOffset?: number, columnOffset?: number): void;
|
|
62
|
+
_indexedMappingsToInt32Array(mappings: Array<IndexedMapping<string>>, lineOffset?: number, columnOffset?: number): Int32Array;
|
|
63
|
+
/**
|
|
64
|
+
* Appends an array of Mapping objects to this sourcemap
|
|
65
|
+
* This is useful when improving performance if a library provides the non-serialised mappings
|
|
66
|
+
*
|
|
67
|
+
* Note: This is only faster if they generate the serialised map lazily
|
|
68
|
+
* Note: line numbers start at 1 due to mozilla's source-map library
|
|
69
|
+
*
|
|
70
|
+
* @param mappings an array of mapping objects
|
|
71
|
+
* @param lineOffset an offset that gets added to the sourceLine index of each mapping
|
|
72
|
+
* @param columnOffset an offset that gets added to the sourceColumn index of each mapping
|
|
73
|
+
*/
|
|
74
|
+
addIndexedMappings(mappings: Array<IndexedMapping<string>>, lineOffset?: number, columnOffset?: number): SourceMap;
|
|
75
|
+
/**
|
|
76
|
+
* Appends a name to the sourcemap
|
|
77
|
+
*
|
|
78
|
+
* @param name the name that should be appended to the names array
|
|
79
|
+
* @returns the index of the added name in the names array
|
|
80
|
+
*/
|
|
81
|
+
addName(name: string): number;
|
|
82
|
+
/**
|
|
83
|
+
* Appends an array of names to the sourcemap's names array
|
|
84
|
+
*
|
|
85
|
+
* @param names an array of names to add to the sourcemap
|
|
86
|
+
* @returns an array of indexes of the names in the sourcemap's names array, has the same order as the provided names array
|
|
87
|
+
*/
|
|
88
|
+
addNames(names: Array<string>): Array<number>;
|
|
89
|
+
/**
|
|
90
|
+
* Appends a source to the sourcemap's sources array
|
|
91
|
+
*
|
|
92
|
+
* @param source a filepath that should be appended to the sources array
|
|
93
|
+
* @returns the index of the added source filepath in the sources array
|
|
94
|
+
*/
|
|
95
|
+
addSource(source: string): number;
|
|
96
|
+
/**
|
|
97
|
+
* Appends an array of sources to the sourcemap's sources array
|
|
98
|
+
*
|
|
99
|
+
* @param sources an array of filepaths which should sbe appended to the sources array
|
|
100
|
+
* @returns an array of indexes of the sources that have been added to the sourcemap, returned in the same order as provided in the argument
|
|
101
|
+
*/
|
|
102
|
+
addSources(sources: Array<string>): Array<number>;
|
|
103
|
+
/**
|
|
104
|
+
* Get the index in the sources array for a certain source file filepath
|
|
105
|
+
*
|
|
106
|
+
* @param source the filepath of the source file
|
|
107
|
+
*/
|
|
108
|
+
getSourceIndex(source: string): number;
|
|
109
|
+
/**
|
|
110
|
+
* Get the source file filepath for a certain index of the sources array
|
|
111
|
+
*
|
|
112
|
+
* @param index the index of the source in the sources array
|
|
113
|
+
*/
|
|
114
|
+
getSource(index: number): string;
|
|
115
|
+
/**
|
|
116
|
+
* Get a list of all sources
|
|
117
|
+
*/
|
|
118
|
+
getSources(): Array<string>;
|
|
119
|
+
/**
|
|
120
|
+
* Set the sourceContent for a certain file
|
|
121
|
+
* this is optional and is only recommended for files that we cannot read in at the end when we serialise the sourcemap
|
|
122
|
+
*
|
|
123
|
+
* @param sourceName the path of the sourceFile
|
|
124
|
+
* @param sourceContent the content of the sourceFile
|
|
125
|
+
*/
|
|
126
|
+
setSourceContent(sourceName: string, sourceContent: string): void;
|
|
127
|
+
/**
|
|
128
|
+
* Get the content of a source file if it is inlined as part of the source-map
|
|
129
|
+
*
|
|
130
|
+
* @param sourceName filename
|
|
131
|
+
*/
|
|
132
|
+
getSourceContent(sourceName: string): string | null;
|
|
133
|
+
/**
|
|
134
|
+
* Get a list of all sources
|
|
135
|
+
*/
|
|
136
|
+
getSourcesContent(): Array<string | null>;
|
|
137
|
+
/**
|
|
138
|
+
* Get a map of the source and it's corresponding source content
|
|
139
|
+
*/
|
|
140
|
+
getSourcesContentMap(): {
|
|
141
|
+
[key: string]: string | null;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Get the index in the names array for a certain name
|
|
145
|
+
*
|
|
146
|
+
* @param name the name you want to find the index of
|
|
147
|
+
*/
|
|
148
|
+
getNameIndex(name: string): number;
|
|
149
|
+
/**
|
|
150
|
+
* Get the name for a certain index of the names array
|
|
151
|
+
*
|
|
152
|
+
* @param index the index of the name in the names array
|
|
153
|
+
*/
|
|
154
|
+
getName(index: number): string;
|
|
155
|
+
/**
|
|
156
|
+
* Get a list of all names
|
|
157
|
+
*/
|
|
158
|
+
getNames(): Array<string>;
|
|
159
|
+
/**
|
|
160
|
+
* Get a list of all mappings
|
|
161
|
+
*/
|
|
162
|
+
getMappings(): Array<IndexedMapping<number>>;
|
|
163
|
+
/**
|
|
164
|
+
* Convert a Mapping object that uses indexes for name and source to the actual value of name and source
|
|
165
|
+
*
|
|
166
|
+
* Note: This is only used internally, should not be used externally and will probably eventually get
|
|
167
|
+
* handled directly in C++ for improved performance
|
|
168
|
+
*
|
|
169
|
+
* @param index the Mapping that should get converted to a string-based Mapping
|
|
170
|
+
*/
|
|
171
|
+
indexedMappingToStringMapping(mapping: IndexedMapping<number>): IndexedMapping<string> | null;
|
|
172
|
+
/**
|
|
173
|
+
* Remaps original positions from this map to the ones in the provided map
|
|
174
|
+
*
|
|
175
|
+
* This works by finding the closest generated mapping in the provided map
|
|
176
|
+
* to original mappings of this map and remapping those to be the original
|
|
177
|
+
* mapping of the provided map.
|
|
178
|
+
*
|
|
179
|
+
* @param buffer exported SourceMap as a buffer
|
|
180
|
+
*/
|
|
181
|
+
extends(buffer: Buffer | SourceMap): SourceMap;
|
|
182
|
+
/**
|
|
183
|
+
* Returns an object with mappings, sources and names
|
|
184
|
+
* This should only be used for tests, debugging and visualising sourcemaps
|
|
185
|
+
*
|
|
186
|
+
* Note: This is a fairly slow operation
|
|
187
|
+
*/
|
|
188
|
+
getMap(): ParsedMap;
|
|
189
|
+
/**
|
|
190
|
+
* Searches through the sourcemap and returns a mapping that is close to the provided generated line and column
|
|
191
|
+
*
|
|
192
|
+
* @param line the line in the generated code (starts at 1)
|
|
193
|
+
* @param column the column in the generated code (starts at 0)
|
|
194
|
+
*/
|
|
195
|
+
findClosestMapping(line: number, column: number): IndexedMapping<string> | null;
|
|
196
|
+
/**
|
|
197
|
+
* Offset mapping lines from a certain position
|
|
198
|
+
*
|
|
199
|
+
* @param line the line in the generated code (starts at 1)
|
|
200
|
+
* @param lineOffset the amount of lines to offset mappings by
|
|
201
|
+
*/
|
|
202
|
+
offsetLines(line: number, lineOffset: number): void;
|
|
203
|
+
/**
|
|
204
|
+
* Offset mapping columns from a certain position
|
|
205
|
+
*
|
|
206
|
+
* @param line the line in the generated code (starts at 1)
|
|
207
|
+
* @param column the column in the generated code (starts at 0)
|
|
208
|
+
* @param columnOffset the amount of columns to offset mappings by
|
|
209
|
+
*/
|
|
210
|
+
offsetColumns(line: number, column: number, columnOffset: number): void;
|
|
211
|
+
/**
|
|
212
|
+
* Returns a buffer that represents this sourcemap, used for caching
|
|
213
|
+
*/
|
|
214
|
+
toBuffer(): Buffer;
|
|
215
|
+
/**
|
|
216
|
+
* Returns a serialised map using VLQ Mappings
|
|
217
|
+
*/
|
|
218
|
+
toVLQ(): VLQMap;
|
|
219
|
+
/**
|
|
220
|
+
* A function that has to be called at the end of the SourceMap's lifecycle to ensure all memory and native bindings get de-allocated
|
|
221
|
+
*/
|
|
222
|
+
delete(): void;
|
|
223
|
+
/**
|
|
224
|
+
* Returns a serialised map
|
|
225
|
+
*
|
|
226
|
+
* @param options options used for formatting the serialised map
|
|
227
|
+
*/
|
|
228
|
+
stringify(options: SourceMapStringifyOptions): Promise<string | VLQMap>;
|
|
229
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { VLQMap, GenerateEmptyMapOptions } from './types';
|
|
2
|
+
import SourceMap from './SourceMap';
|
|
3
|
+
export type * from './types';
|
|
4
|
+
export default class NodeSourceMap extends SourceMap {
|
|
5
|
+
constructor(projectRoot?: string, buffer?: Buffer);
|
|
6
|
+
addVLQMap(map: VLQMap, lineOffset?: number, columnOffset?: number): SourceMap;
|
|
7
|
+
addSourceMap(sourcemap: SourceMap, lineOffset?: number): SourceMap;
|
|
8
|
+
addBuffer(buffer: Buffer, lineOffset?: number): SourceMap;
|
|
9
|
+
extends(input: Buffer | SourceMap): SourceMap;
|
|
10
|
+
getNames(): Array<string>;
|
|
11
|
+
getSources(): Array<string>;
|
|
12
|
+
delete(): void;
|
|
13
|
+
static generateEmptyMap({ projectRoot, sourceName, sourceContent, lineOffset, }: GenerateEmptyMapOptions): NodeSourceMap;
|
|
14
|
+
static safeToBuffer<T extends SourceMap>(sourceMap: T | null | undefined): Buffer | undefined;
|
|
15
|
+
}
|
|
16
|
+
export declare const init: Promise<void>;
|
|
17
|
+
export type { SourceMap };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export interface MappingPosition {
|
|
2
|
+
line: number;
|
|
3
|
+
column: number;
|
|
4
|
+
}
|
|
5
|
+
export interface IndexedMapping<T> {
|
|
6
|
+
generated: MappingPosition;
|
|
7
|
+
original?: MappingPosition;
|
|
8
|
+
source?: T;
|
|
9
|
+
name?: T;
|
|
10
|
+
}
|
|
11
|
+
export interface ParsedMap {
|
|
12
|
+
sources: Array<string>;
|
|
13
|
+
names: Array<string>;
|
|
14
|
+
mappings: Array<IndexedMapping<number>>;
|
|
15
|
+
sourcesContent: Array<string | null>;
|
|
16
|
+
}
|
|
17
|
+
export interface VLQMap {
|
|
18
|
+
sources: readonly string[];
|
|
19
|
+
sourcesContent?: readonly (string | null)[];
|
|
20
|
+
names: readonly string[];
|
|
21
|
+
mappings: string;
|
|
22
|
+
version?: number;
|
|
23
|
+
file?: string;
|
|
24
|
+
sourceRoot?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface SourceMapStringifyOptions {
|
|
27
|
+
file?: string;
|
|
28
|
+
sourceRoot?: string;
|
|
29
|
+
inlineSources?: boolean;
|
|
30
|
+
fs?: {
|
|
31
|
+
readFile(path: string, encoding: string): Promise<string>;
|
|
32
|
+
};
|
|
33
|
+
format?: 'inline' | 'string' | 'object';
|
|
34
|
+
/**
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
rootDir?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface GenerateEmptyMapOptions {
|
|
40
|
+
projectRoot: string;
|
|
41
|
+
sourceName: string;
|
|
42
|
+
sourceContent: string;
|
|
43
|
+
lineOffset?: number;
|
|
44
|
+
}
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateInlineMap = generateInlineMap;
|
|
7
|
+
exports.partialVlqMapToSourceMap = partialVlqMapToSourceMap;
|
|
8
|
+
function _path() {
|
|
9
|
+
const data = _interopRequireDefault(require("path"));
|
|
10
|
+
_path = function () {
|
|
11
|
+
return data;
|
|
12
|
+
};
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function generateInlineMap(map) {
|
|
17
|
+
return `data:application/json;charset=utf-8;base64,${Buffer.from(map).toString('base64')}`;
|
|
18
|
+
}
|
|
19
|
+
async function partialVlqMapToSourceMap(map, opts) {
|
|
20
|
+
let {
|
|
21
|
+
fs,
|
|
22
|
+
file,
|
|
23
|
+
sourceRoot,
|
|
24
|
+
inlineSources,
|
|
25
|
+
rootDir,
|
|
26
|
+
format = 'string'
|
|
27
|
+
} = opts;
|
|
28
|
+
let resultMap = {
|
|
29
|
+
...map,
|
|
30
|
+
sourcesContent: map.sourcesContent ? map.sourcesContent.map(content => {
|
|
31
|
+
if (content) {
|
|
32
|
+
return content;
|
|
33
|
+
} else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}) : [],
|
|
37
|
+
version: 3,
|
|
38
|
+
file,
|
|
39
|
+
sourceRoot
|
|
40
|
+
};
|
|
41
|
+
if (resultMap.sourcesContent.length < resultMap.sources.length) {
|
|
42
|
+
for (let i = 0; i <= resultMap.sources.length - resultMap.sourcesContent.length; i++) {
|
|
43
|
+
resultMap.sourcesContent.push(null);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (fs) {
|
|
47
|
+
resultMap.sourcesContent = await Promise.all(resultMap.sourcesContent.map(async (content, index) => {
|
|
48
|
+
let sourceName = map.sources[index];
|
|
49
|
+
// If sourceName starts with `..` it is outside rootDir, in this case we likely cannot access this file from the browser or packaged node_module
|
|
50
|
+
// Because of this we have to include the sourceContent to ensure you can always see the sourcecontent for each mapping.
|
|
51
|
+
if (!content && (inlineSources || sourceName.startsWith('..'))) {
|
|
52
|
+
try {
|
|
53
|
+
return await fs.readFile(_path().default.resolve(rootDir || '/', sourceName), 'utf-8');
|
|
54
|
+
} catch (e) {
|
|
55
|
+
/* empty */
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return content;
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
if (format === 'inline' || format === 'string') {
|
|
62
|
+
let stringifiedMap = JSON.stringify(resultMap);
|
|
63
|
+
if (format === 'inline') {
|
|
64
|
+
return generateInlineMap(stringifiedMap);
|
|
65
|
+
}
|
|
66
|
+
return stringifiedMap;
|
|
67
|
+
}
|
|
68
|
+
return resultMap;
|
|
69
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaspack/source-map",
|
|
3
|
+
"version": "3.0.1-canary.4070+31c12bc28",
|
|
4
|
+
"license": "(MIT OR Apache-2.0)",
|
|
5
|
+
"type": "commonjs",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
12
|
+
},
|
|
13
|
+
"main": "./lib/node.js",
|
|
14
|
+
"source": "./src/node.ts",
|
|
15
|
+
"types": "./lib/types/node.d.ts",
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">= 16.0.0"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src",
|
|
21
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@atlaspack/rust": "3.2.1-canary.291+31c12bc28"
|
|
25
|
+
},
|
|
26
|
+
"gitHead": "31c12bc28d861d4ce80446afffc18cb0c7b4ebd3"
|
|
27
|
+
}
|