@atlaspack/utils 2.14.5-canary.21 → 2.14.5-canary.211
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/CHANGELOG.md +272 -0
- package/benchmark.js +23 -0
- package/dist/DefaultMap.js +41 -0
- package/dist/Deferred.js +16 -0
- package/dist/PromiseQueue.js +107 -0
- package/dist/TapStream.js +23 -0
- package/dist/alternatives.js +97 -0
- package/dist/ansi-html.js +12 -0
- package/dist/blob.js +29 -0
- package/dist/bundle-url.js +32 -0
- package/dist/collection.js +106 -0
- package/dist/config.js +138 -0
- package/dist/countLines.js +12 -0
- package/dist/debounce.js +15 -0
- package/dist/debug-tools.js +38 -0
- package/dist/dependency-location.js +22 -0
- package/dist/escape-html.js +19 -0
- package/dist/generateBuildMetrics.js +111 -0
- package/dist/generateCertificate.js +124 -0
- package/dist/getCertificate.js +13 -0
- package/dist/getExisting.js +20 -0
- package/dist/getModuleParts.js +27 -0
- package/dist/getRootDir.js +46 -0
- package/dist/glob.js +129 -0
- package/dist/hash.js +45 -0
- package/dist/http-server.js +55 -0
- package/dist/index.js +146 -0
- package/dist/is-url.js +15 -0
- package/dist/isDirectoryInside.js +11 -0
- package/dist/objectHash.js +20 -0
- package/dist/openInBrowser.js +61 -0
- package/dist/parseCSSImport.js +14 -0
- package/dist/path.js +36 -0
- package/dist/prettifyTime.js +6 -0
- package/dist/prettyDiagnostic.js +104 -0
- package/dist/progress-message.js +31 -0
- package/dist/relativeBundlePath.js +13 -0
- package/dist/relativeUrl.js +11 -0
- package/dist/replaceBundleReferences.js +140 -0
- package/dist/schema.js +389 -0
- package/dist/shared-buffer.js +24 -0
- package/dist/sourcemap.js +121 -0
- package/dist/stream.js +69 -0
- package/dist/throttle.js +12 -0
- package/dist/urlJoin.js +22 -0
- package/lib/DefaultMap.js +42 -0
- package/lib/Deferred.js +30 -0
- package/lib/PromiseQueue.js +112 -0
- package/lib/TapStream.js +34 -0
- package/lib/alternatives.js +116 -0
- package/lib/ansi-html.js +20 -0
- package/lib/blob.js +40 -0
- package/lib/bundle-url.js +34 -0
- package/lib/collection.js +111 -0
- package/lib/config.js +174 -0
- package/lib/countLines.js +15 -0
- package/lib/debounce.js +18 -0
- package/lib/debug-tools.js +39 -0
- package/lib/dependency-location.js +21 -0
- package/lib/escape-html.js +22 -0
- package/lib/generateBuildMetrics.js +121 -0
- package/lib/generateCertificate.js +129 -0
- package/lib/getCertificate.js +18 -0
- package/lib/getExisting.js +25 -0
- package/lib/getModuleParts.js +30 -0
- package/lib/getRootDir.js +52 -0
- package/lib/glob.js +110 -0
- package/lib/hash.js +50 -0
- package/lib/http-server.js +85 -0
- package/lib/index.js +635 -37310
- package/lib/is-url.js +24 -0
- package/lib/isDirectoryInside.js +18 -0
- package/lib/objectHash.js +26 -0
- package/lib/openInBrowser.js +74 -0
- package/lib/parseCSSImport.js +15 -0
- package/lib/path.js +39 -0
- package/lib/prettifyTime.js +9 -0
- package/lib/prettyDiagnostic.js +150 -0
- package/lib/progress-message.js +39 -0
- package/lib/relativeBundlePath.js +22 -0
- package/lib/relativeUrl.js +24 -0
- package/lib/replaceBundleReferences.js +199 -0
- package/lib/schema.js +355 -0
- package/lib/shared-buffer.js +31 -0
- package/lib/sourcemap.js +138 -0
- package/lib/stream.js +76 -0
- package/lib/throttle.js +15 -0
- package/lib/types/DefaultMap.d.ts +13 -0
- package/lib/types/Deferred.d.ts +8 -0
- package/lib/types/PromiseQueue.d.ts +25 -0
- package/lib/types/TapStream.d.ts +6 -0
- package/lib/types/alternatives.d.ts +3 -0
- package/lib/types/ansi-html.d.ts +1 -0
- package/lib/types/blob.d.ts +4 -0
- package/lib/types/bundle-url.d.ts +4 -0
- package/lib/types/collection.d.ts +33 -0
- package/lib/types/config.d.ts +17 -0
- package/lib/types/countLines.d.ts +1 -0
- package/lib/types/debounce.d.ts +1 -0
- package/lib/types/debug-tools.d.ts +7 -0
- package/lib/types/dependency-location.d.ts +14 -0
- package/lib/types/escape-html.d.ts +1 -0
- package/lib/types/generateBuildMetrics.d.ts +18 -0
- package/lib/types/generateCertificate.d.ts +5 -0
- package/lib/types/getCertificate.d.ts +5 -0
- package/lib/types/getExisting.d.ts +8 -0
- package/lib/types/getModuleParts.d.ts +4 -0
- package/lib/types/getRootDir.d.ts +2 -0
- package/lib/types/glob.d.ts +9 -0
- package/lib/types/hash.d.ts +7 -0
- package/lib/types/http-server.d.ts +19 -0
- package/lib/types/index.d.ts +48 -0
- package/lib/types/is-url.d.ts +1 -0
- package/lib/types/isDirectoryInside.d.ts +2 -0
- package/lib/types/objectHash.d.ts +3 -0
- package/lib/types/openInBrowser.d.ts +1 -0
- package/lib/types/parseCSSImport.d.ts +1 -0
- package/lib/types/path.d.ts +8 -0
- package/lib/types/prettifyTime.d.ts +1 -0
- package/lib/types/prettyDiagnostic.d.ts +17 -0
- package/lib/types/progress-message.d.ts +3 -0
- package/lib/types/relativeBundlePath.d.ts +4 -0
- package/lib/types/relativeUrl.d.ts +1 -0
- package/lib/types/replaceBundleReferences.d.ts +39 -0
- package/lib/types/schema.d.ts +107 -0
- package/lib/types/shared-buffer.d.ts +2 -0
- package/lib/types/sourcemap.d.ts +15 -0
- package/lib/types/stream.d.ts +8 -0
- package/lib/types/throttle.d.ts +1 -0
- package/lib/types/urlJoin.d.ts +5 -0
- package/lib/urlJoin.js +35 -0
- package/package.json +26 -17
- package/src/{DefaultMap.js → DefaultMap.ts} +8 -12
- package/src/Deferred.ts +26 -0
- package/src/{PromiseQueue.js → PromiseQueue.ts} +40 -35
- package/src/{TapStream.js → TapStream.ts} +8 -7
- package/src/{alternatives.js → alternatives.ts} +15 -16
- package/src/{ansi-html.js → ansi-html.ts} +1 -1
- package/src/{blob.js → blob.ts} +3 -5
- package/src/{bundle-url.js → bundle-url.ts} +3 -5
- package/src/{collection.js → collection.ts} +23 -20
- package/src/{config.js → config.ts} +20 -21
- package/src/{countLines.js → countLines.ts} +0 -2
- package/src/{debounce.js → debounce.ts} +3 -5
- package/src/debug-tools.ts +46 -0
- package/src/{dependency-location.js → dependency-location.ts} +15 -11
- package/src/{escape-html.js → escape-html.ts} +5 -3
- package/src/{generateBuildMetrics.js → generateBuildMetrics.ts} +18 -20
- package/src/{generateCertificate.js → generateCertificate.ts} +8 -6
- package/src/{getCertificate.js → getCertificate.ts} +6 -5
- package/src/{getExisting.js → getExisting.ts} +4 -3
- package/src/{getModuleParts.js → getModuleParts.ts} +3 -2
- package/src/{getRootDir.js → getRootDir.ts} +1 -3
- package/src/{glob.js → glob.ts} +13 -14
- package/src/{hash.js → hash.ts} +23 -18
- package/src/{http-server.js → http-server.ts} +34 -40
- package/src/{index.js → index.ts} +13 -9
- package/src/{is-url.js → is-url.ts} +1 -2
- package/src/{isDirectoryInside.js → isDirectoryInside.ts} +1 -2
- package/src/{objectHash.js → objectHash.ts} +1 -4
- package/src/{openInBrowser.js → openInBrowser.ts} +2 -4
- package/src/{parseCSSImport.js → parseCSSImport.ts} +0 -2
- package/src/{path.js → path.ts} +2 -4
- package/src/{prettifyTime.js → prettifyTime.ts} +0 -2
- package/src/{prettyDiagnostic.js → prettyDiagnostic.ts} +34 -22
- package/src/progress-message.ts +43 -0
- package/src/{relativeBundlePath.js → relativeBundlePath.ts} +4 -4
- package/src/{relativeUrl.js → relativeUrl.ts} +0 -1
- package/src/{replaceBundleReferences.js → replaceBundleReferences.ts} +63 -39
- package/src/{schema.js → schema.ts} +158 -141
- package/src/{shared-buffer.js → shared-buffer.ts} +5 -3
- package/src/{sourcemap.js → sourcemap.ts} +27 -9
- package/src/{stream.js → stream.ts} +30 -22
- package/src/throttle.ts +13 -0
- package/src/{urlJoin.js → urlJoin.ts} +1 -3
- package/test/{DefaultMap.test.js → DefaultMap.test.ts} +4 -6
- package/test/{PromiseQueue.test.js → PromiseQueue.test.ts} +5 -6
- package/test/{collection.test.js → collection.test.ts} +0 -2
- package/test/{config.test.js → config.test.ts} +0 -3
- package/test/{objectHash.test.js → objectHash.test.ts} +4 -5
- package/test/{prettifyTime.test.js → prettifyTime.test.ts} +0 -1
- package/test/{replaceBundleReferences.test.js → replaceBundleReferences.test.ts} +0 -32
- package/test/{sourcemap.test.js → sourcemap.test.ts} +0 -1
- package/test/{throttle.test.js → throttle.test.ts} +1 -3
- package/test/{urlJoin.test.js → urlJoin.test.ts} +0 -2
- package/tsconfig.json +33 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/lib/index.js.map +0 -1
- package/src/Deferred.js +0 -23
- package/src/progress-message.js +0 -22
- package/src/throttle.js +0 -15
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.debugTools = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* These tools are intended for Atlaspack developers, to provide extra utilities
|
|
9
|
+
* to make debugging Atlaspack issues more straightforward.
|
|
10
|
+
*
|
|
11
|
+
* To enable a tool, set the `ATLASPACK_DEBUG_TOOLS` environment variable to a
|
|
12
|
+
* comma-separated list of tool names. For example:
|
|
13
|
+
* `ATLASPACK_DEBUG_TOOLS="asset-file-names-in-output,simple-cli-reporter"`
|
|
14
|
+
*
|
|
15
|
+
* You can enable all tools by setting `ATLASPACK_DEBUG_TOOLS=all`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
let debugTools = exports.debugTools = {
|
|
19
|
+
'asset-file-names-in-output': false,
|
|
20
|
+
'simple-cli-reporter': false,
|
|
21
|
+
'bundle-stats': false
|
|
22
|
+
};
|
|
23
|
+
const envVarValue = process.env.ATLASPACK_DEBUG_TOOLS ?? '';
|
|
24
|
+
for (let tool of envVarValue.split(',')) {
|
|
25
|
+
tool = tool.trim();
|
|
26
|
+
if (tool === 'all') {
|
|
27
|
+
for (let key in debugTools) {
|
|
28
|
+
debugTools[key] = true;
|
|
29
|
+
}
|
|
30
|
+
break;
|
|
31
|
+
} else if (debugTools.hasOwnProperty(tool)) {
|
|
32
|
+
debugTools[tool] = true;
|
|
33
|
+
} else if (tool === '') {
|
|
34
|
+
continue;
|
|
35
|
+
} else {
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.warn(`Unknown debug tool option: ${tool}. Valid options are: ${Object.keys(debugTools).join(', ')}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = createDependencyLocation;
|
|
7
|
+
function createDependencyLocation(start, specifier, lineOffset = 0, columnOffset = 0,
|
|
8
|
+
// Imports are usually wrapped in quotes
|
|
9
|
+
importWrapperLength = 2) {
|
|
10
|
+
return {
|
|
11
|
+
filePath: specifier,
|
|
12
|
+
start: {
|
|
13
|
+
line: start.line + lineOffset,
|
|
14
|
+
column: start.column + columnOffset
|
|
15
|
+
},
|
|
16
|
+
end: {
|
|
17
|
+
line: start.line + lineOffset,
|
|
18
|
+
column: start.column + specifier.length - 1 + importWrapperLength + columnOffset
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.escapeHTML = escapeHTML;
|
|
7
|
+
// Based on _.escape https://github.com/lodash/lodash/blob/master/escape.js
|
|
8
|
+
const reUnescapedHtml = /[&<>"']/g;
|
|
9
|
+
const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
|
|
10
|
+
const htmlEscapes = {
|
|
11
|
+
'&': '&',
|
|
12
|
+
'<': '<',
|
|
13
|
+
'>': '>',
|
|
14
|
+
'"': '"',
|
|
15
|
+
"'": '''
|
|
16
|
+
};
|
|
17
|
+
function escapeHTML(s) {
|
|
18
|
+
if (reHasUnescapedHtml.test(s)) {
|
|
19
|
+
return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
|
|
20
|
+
}
|
|
21
|
+
return s;
|
|
22
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = generateBuildMetrics;
|
|
7
|
+
function _sourceMap() {
|
|
8
|
+
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
9
|
+
_sourceMap = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _nullthrows() {
|
|
15
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
16
|
+
_nullthrows = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _path() {
|
|
22
|
+
const data = _interopRequireDefault(require("path"));
|
|
23
|
+
_path = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
var _ = require("./");
|
|
29
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
30
|
+
async function getSourcemapSizes(filePath, fs, projectRoot) {
|
|
31
|
+
let bundleContents = await fs.readFile(filePath, 'utf-8');
|
|
32
|
+
let mapUrlData = await (0, _.loadSourceMapUrl)(fs, filePath, bundleContents);
|
|
33
|
+
if (!mapUrlData) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
let rawMap = mapUrlData.map;
|
|
37
|
+
let sourceMap = new (_sourceMap().default)(projectRoot);
|
|
38
|
+
sourceMap.addVLQMap(rawMap);
|
|
39
|
+
let parsedMapData = sourceMap.getMap();
|
|
40
|
+
if (parsedMapData.mappings.length > 2) {
|
|
41
|
+
let sources = parsedMapData.sources.map(s => _path().default.normalize(_path().default.join(projectRoot, s)));
|
|
42
|
+
let currLine = 1;
|
|
43
|
+
let currColumn = 0;
|
|
44
|
+
let currMappingIndex = 0;
|
|
45
|
+
let currMapping = parsedMapData.mappings[currMappingIndex];
|
|
46
|
+
let nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
47
|
+
let sourceSizes = new Array(sources.length).fill(0);
|
|
48
|
+
let unknownOrigin = 0;
|
|
49
|
+
for (let i = 0; i < bundleContents.length; i++) {
|
|
50
|
+
let character = bundleContents[i];
|
|
51
|
+
while (nextMapping && nextMapping.generated.line === currLine && nextMapping.generated.column <= currColumn) {
|
|
52
|
+
currMappingIndex++;
|
|
53
|
+
currMapping = parsedMapData.mappings[currMappingIndex];
|
|
54
|
+
nextMapping = parsedMapData.mappings[currMappingIndex + 1];
|
|
55
|
+
}
|
|
56
|
+
let currentSource = currMapping.source;
|
|
57
|
+
let charSize = Buffer.byteLength(character, 'utf8');
|
|
58
|
+
if (currentSource != null && currMapping.generated.line === currLine && currMapping.generated.column <= currColumn) {
|
|
59
|
+
sourceSizes[currentSource] += charSize;
|
|
60
|
+
} else {
|
|
61
|
+
unknownOrigin += charSize;
|
|
62
|
+
}
|
|
63
|
+
if (character === '\n') {
|
|
64
|
+
currColumn = 0;
|
|
65
|
+
currLine++;
|
|
66
|
+
} else {
|
|
67
|
+
currColumn++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
let sizeMap = new Map();
|
|
71
|
+
for (let i = 0; i < sourceSizes.length; i++) {
|
|
72
|
+
sizeMap.set(sources[i], sourceSizes[i]);
|
|
73
|
+
}
|
|
74
|
+
sizeMap.set('', unknownOrigin);
|
|
75
|
+
return sizeMap;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function createBundleStats(bundle, fs, projectRoot) {
|
|
79
|
+
let filePath = bundle.filePath;
|
|
80
|
+
let sourcemapSizes = await getSourcemapSizes(filePath, fs, projectRoot);
|
|
81
|
+
let assets = new Map();
|
|
82
|
+
bundle.traverseAssets(asset => {
|
|
83
|
+
let filePath = _path().default.normalize(asset.filePath);
|
|
84
|
+
assets.set(filePath, {
|
|
85
|
+
filePath,
|
|
86
|
+
size: asset.stats.size,
|
|
87
|
+
originalSize: asset.stats.size,
|
|
88
|
+
time: asset.stats.time
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
let assetsReport = [];
|
|
92
|
+
if (sourcemapSizes && sourcemapSizes.size) {
|
|
93
|
+
assetsReport = Array.from(sourcemapSizes.keys()).map(filePath => {
|
|
94
|
+
let foundSize = sourcemapSizes.get(filePath) || 0;
|
|
95
|
+
let stats = assets.get(filePath) || {
|
|
96
|
+
filePath,
|
|
97
|
+
size: foundSize,
|
|
98
|
+
originalSize: foundSize,
|
|
99
|
+
time: 0
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
...stats,
|
|
103
|
+
size: foundSize
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
assetsReport = Array.from(assets.values());
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
filePath: (0, _nullthrows().default)(bundle.filePath),
|
|
111
|
+
size: bundle.stats.size,
|
|
112
|
+
time: bundle.stats.time,
|
|
113
|
+
assets: assetsReport.sort((a, b) => b.size - a.size)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
async function generateBuildMetrics(bundles, fs, projectRoot) {
|
|
117
|
+
bundles.sort((a, b) => b.stats.size - a.stats.size).filter(b => !!b.filePath);
|
|
118
|
+
return {
|
|
119
|
+
bundles: (await Promise.all(bundles.map(b => createBundleStats(b, fs, projectRoot)))).filter(e => !!e)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = generateCertificate;
|
|
7
|
+
function _nodeForge() {
|
|
8
|
+
const data = _interopRequireDefault(require("node-forge"));
|
|
9
|
+
_nodeForge = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _path() {
|
|
15
|
+
const data = _interopRequireDefault(require("path"));
|
|
16
|
+
_path = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _logger() {
|
|
22
|
+
const data = _interopRequireDefault(require("@atlaspack/logger"));
|
|
23
|
+
_logger = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
async function generateCertificate(fs, cacheDir, host) {
|
|
30
|
+
let certDirectory = cacheDir;
|
|
31
|
+
const privateKeyPath = _path().default.join(certDirectory, 'private.pem');
|
|
32
|
+
const certPath = _path().default.join(certDirectory, 'primary.crt');
|
|
33
|
+
const cachedKey = (await fs.exists(privateKeyPath)) && (await fs.readFile(privateKeyPath));
|
|
34
|
+
const cachedCert = (await fs.exists(certPath)) && (await fs.readFile(certPath));
|
|
35
|
+
if (cachedKey && cachedCert) {
|
|
36
|
+
return {
|
|
37
|
+
key: cachedKey,
|
|
38
|
+
cert: cachedCert
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
_logger().default.progress('Generating SSL Certificate...');
|
|
42
|
+
const pki = _nodeForge().default.pki;
|
|
43
|
+
const keys = pki.rsa.generateKeyPair(2048);
|
|
44
|
+
const cert = pki.createCertificate();
|
|
45
|
+
cert.publicKey = keys.publicKey;
|
|
46
|
+
cert.serialNumber = Date.now().toString();
|
|
47
|
+
cert.validity.notBefore = new Date();
|
|
48
|
+
cert.validity.notAfter = new Date();
|
|
49
|
+
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
|
|
50
|
+
const attrs = [{
|
|
51
|
+
name: 'commonName',
|
|
52
|
+
value: 'parceljs.org'
|
|
53
|
+
}, {
|
|
54
|
+
name: 'countryName',
|
|
55
|
+
value: 'US'
|
|
56
|
+
}, {
|
|
57
|
+
shortName: 'ST',
|
|
58
|
+
value: 'Virginia'
|
|
59
|
+
}, {
|
|
60
|
+
name: 'localityName',
|
|
61
|
+
value: 'Blacksburg'
|
|
62
|
+
}, {
|
|
63
|
+
name: 'organizationName',
|
|
64
|
+
value: 'parcelBundler'
|
|
65
|
+
}, {
|
|
66
|
+
shortName: 'OU',
|
|
67
|
+
value: 'Test'
|
|
68
|
+
}];
|
|
69
|
+
let altNames = [{
|
|
70
|
+
type: 2,
|
|
71
|
+
// DNS
|
|
72
|
+
value: 'localhost'
|
|
73
|
+
}, {
|
|
74
|
+
type: 7,
|
|
75
|
+
// IP
|
|
76
|
+
ip: '127.0.0.1'
|
|
77
|
+
}];
|
|
78
|
+
if (host) {
|
|
79
|
+
altNames.push({
|
|
80
|
+
type: 2,
|
|
81
|
+
// DNS
|
|
82
|
+
value: host
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
cert.setSubject(attrs);
|
|
86
|
+
cert.setIssuer(attrs);
|
|
87
|
+
cert.setExtensions([{
|
|
88
|
+
name: 'basicConstraints',
|
|
89
|
+
cA: false
|
|
90
|
+
}, {
|
|
91
|
+
name: 'keyUsage',
|
|
92
|
+
keyCertSign: true,
|
|
93
|
+
digitalSignature: true,
|
|
94
|
+
nonRepudiation: true,
|
|
95
|
+
keyEncipherment: true,
|
|
96
|
+
dataEncipherment: true
|
|
97
|
+
}, {
|
|
98
|
+
name: 'extKeyUsage',
|
|
99
|
+
serverAuth: true,
|
|
100
|
+
clientAuth: true,
|
|
101
|
+
codeSigning: true,
|
|
102
|
+
emailProtection: true,
|
|
103
|
+
timeStamping: true
|
|
104
|
+
}, {
|
|
105
|
+
name: 'nsCertType',
|
|
106
|
+
client: true,
|
|
107
|
+
server: true,
|
|
108
|
+
email: true,
|
|
109
|
+
objsign: true,
|
|
110
|
+
sslCA: true,
|
|
111
|
+
emailCA: true,
|
|
112
|
+
objCA: true
|
|
113
|
+
}, {
|
|
114
|
+
name: 'subjectAltName',
|
|
115
|
+
altNames
|
|
116
|
+
}, {
|
|
117
|
+
name: 'subjectKeyIdentifier'
|
|
118
|
+
}]);
|
|
119
|
+
cert.sign(keys.privateKey, _nodeForge().default.md.sha256.create());
|
|
120
|
+
const privPem = pki.privateKeyToPem(keys.privateKey);
|
|
121
|
+
const certPem = pki.certificateToPem(cert);
|
|
122
|
+
await fs.mkdirp(certDirectory);
|
|
123
|
+
await fs.writeFile(privateKeyPath, privPem);
|
|
124
|
+
await fs.writeFile(certPath, certPem);
|
|
125
|
+
return {
|
|
126
|
+
key: privPem,
|
|
127
|
+
cert: certPem
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getCertificate;
|
|
7
|
+
async function getCertificate(fs, options) {
|
|
8
|
+
try {
|
|
9
|
+
let cert = await fs.readFile(options.cert);
|
|
10
|
+
let key = await fs.readFile(options.key);
|
|
11
|
+
return {
|
|
12
|
+
key,
|
|
13
|
+
cert
|
|
14
|
+
};
|
|
15
|
+
} catch (err) {
|
|
16
|
+
throw new Error('Certificate and/or key not found');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getExisting;
|
|
7
|
+
function _fs() {
|
|
8
|
+
const data = _interopRequireDefault(require("fs"));
|
|
9
|
+
_fs = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
/**
|
|
16
|
+
* Creates an object that contains both source and minified (using the source as a fallback).
|
|
17
|
+
* e.g. builtins.min.js and builtins.js.
|
|
18
|
+
*/
|
|
19
|
+
function getExisting(minifiedPath, sourcePath) {
|
|
20
|
+
let source = _fs().default.readFileSync(sourcePath, 'utf8').trim();
|
|
21
|
+
return {
|
|
22
|
+
source,
|
|
23
|
+
minified: _fs().default.existsSync(minifiedPath) ? _fs().default.readFileSync(minifiedPath, 'utf8').trim().replace(/;$/, '') : source
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getModuleParts;
|
|
7
|
+
function _path() {
|
|
8
|
+
const data = _interopRequireDefault(require("path"));
|
|
9
|
+
_path = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
var _path2 = require("./path");
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
/**
|
|
17
|
+
* Returns the package name and the optional subpath
|
|
18
|
+
*/
|
|
19
|
+
function getModuleParts(_name) {
|
|
20
|
+
let name = _path().default.normalize(_name);
|
|
21
|
+
let splitOn = name.indexOf(_path().default.sep);
|
|
22
|
+
if (name.charAt(0) === '@') {
|
|
23
|
+
splitOn = name.indexOf(_path().default.sep, splitOn + 1);
|
|
24
|
+
}
|
|
25
|
+
if (splitOn < 0) {
|
|
26
|
+
return [(0, _path2.normalizeSeparators)(name), undefined];
|
|
27
|
+
} else {
|
|
28
|
+
return [(0, _path2.normalizeSeparators)(name.substring(0, splitOn)), name.substring(splitOn + 1) || undefined];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getRootDir;
|
|
7
|
+
var _glob = require("./glob");
|
|
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 getRootDir(files) {
|
|
17
|
+
let cur = null;
|
|
18
|
+
for (let file of files) {
|
|
19
|
+
let parsed = _path().default.parse(file);
|
|
20
|
+
parsed.dir = findGlobRoot(parsed.dir);
|
|
21
|
+
if (!cur) {
|
|
22
|
+
cur = parsed;
|
|
23
|
+
} else if (parsed.root !== cur.root) {
|
|
24
|
+
// bail out. there is no common root.
|
|
25
|
+
// this can happen on windows, e.g. C:\foo\bar vs. D:\foo\bar
|
|
26
|
+
return process.cwd();
|
|
27
|
+
} else {
|
|
28
|
+
// find the common path parts.
|
|
29
|
+
let curParts = cur.dir.split(_path().default.sep);
|
|
30
|
+
let newParts = parsed.dir.split(_path().default.sep);
|
|
31
|
+
let len = Math.min(curParts.length, newParts.length);
|
|
32
|
+
let i = 0;
|
|
33
|
+
while (i < len && curParts[i] === newParts[i]) {
|
|
34
|
+
i++;
|
|
35
|
+
}
|
|
36
|
+
cur.dir = i > 1 ? curParts.slice(0, i).join(_path().default.sep) : cur.root;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return cur ? cur.dir : process.cwd();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Transforms a path like `packages/*/src/index.js` to the root of the glob, `packages/`
|
|
43
|
+
function findGlobRoot(dir) {
|
|
44
|
+
let parts = dir.split(_path().default.sep);
|
|
45
|
+
let last = parts.length;
|
|
46
|
+
for (let i = parts.length - 1; i >= 0; i--) {
|
|
47
|
+
if ((0, _glob.isGlob)(parts[i])) {
|
|
48
|
+
last = i;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return parts.slice(0, last).join(_path().default.sep);
|
|
52
|
+
}
|
package/lib/glob.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.glob = glob;
|
|
7
|
+
exports.globMatch = globMatch;
|
|
8
|
+
exports.globSync = globSync;
|
|
9
|
+
exports.globToRegex = globToRegex;
|
|
10
|
+
exports.isGlob = isGlob;
|
|
11
|
+
exports.isGlobMatch = isGlobMatch;
|
|
12
|
+
function _isGlob2() {
|
|
13
|
+
const data = _interopRequireDefault(require("is-glob"));
|
|
14
|
+
_isGlob2 = function () {
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
function _fastGlob() {
|
|
20
|
+
const data = _interopRequireDefault(require("fast-glob"));
|
|
21
|
+
_fastGlob = function () {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
function _micromatch() {
|
|
27
|
+
const data = _interopRequireWildcard(require("micromatch"));
|
|
28
|
+
_micromatch = function () {
|
|
29
|
+
return data;
|
|
30
|
+
};
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
var _path = require("./path");
|
|
34
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
35
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
36
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
+
function isGlob(p) {
|
|
38
|
+
return (0, _isGlob2().default)((0, _path.normalizeSeparators)(p));
|
|
39
|
+
}
|
|
40
|
+
function isGlobMatch(filePath, glob, opts) {
|
|
41
|
+
glob = Array.isArray(glob) ? glob.map(_path.normalizeSeparators) : (0, _path.normalizeSeparators)(glob);
|
|
42
|
+
return (0, _micromatch().isMatch)(filePath, glob, opts);
|
|
43
|
+
}
|
|
44
|
+
function globMatch(values, glob, opts) {
|
|
45
|
+
glob = Array.isArray(glob) ? glob.map(_path.normalizeSeparators) : (0, _path.normalizeSeparators)(glob);
|
|
46
|
+
return (0, _micromatch().default)(values, glob, opts);
|
|
47
|
+
}
|
|
48
|
+
function globToRegex(glob, opts) {
|
|
49
|
+
return (0, _micromatch().makeRe)(glob, opts);
|
|
50
|
+
}
|
|
51
|
+
function globSync(p, fs, options) {
|
|
52
|
+
options = {
|
|
53
|
+
...options,
|
|
54
|
+
fs: {
|
|
55
|
+
statSync: p => {
|
|
56
|
+
return fs.statSync(p);
|
|
57
|
+
},
|
|
58
|
+
lstatSync: p => {
|
|
59
|
+
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
60
|
+
// but this is fine for our purposes since we follow symlinks by default.
|
|
61
|
+
return fs.statSync(p);
|
|
62
|
+
},
|
|
63
|
+
// @ts-expect-error TS7006
|
|
64
|
+
readdirSync: (p, opts) => {
|
|
65
|
+
return fs.readdirSync(p, opts);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
return _fastGlob().default.sync((0, _path.normalizeSeparators)(p), options);
|
|
70
|
+
}
|
|
71
|
+
function glob(p, fs, options) {
|
|
72
|
+
options = {
|
|
73
|
+
...options,
|
|
74
|
+
fs: {
|
|
75
|
+
stat: async (p, cb) => {
|
|
76
|
+
try {
|
|
77
|
+
cb(null, await fs.stat(p));
|
|
78
|
+
} catch (err) {
|
|
79
|
+
// @ts-expect-error TS2345
|
|
80
|
+
cb(err);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
lstat: async (p, cb) => {
|
|
84
|
+
// Our FileSystem interface doesn't have lstat support at the moment,
|
|
85
|
+
// but this is fine for our purposes since we follow symlinks by default.
|
|
86
|
+
try {
|
|
87
|
+
cb(null, await fs.stat(p));
|
|
88
|
+
} catch (err) {
|
|
89
|
+
// @ts-expect-error TS2345
|
|
90
|
+
cb(err);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
// @ts-expect-error TS7006
|
|
94
|
+
readdir: async (p, opts, cb) => {
|
|
95
|
+
if (typeof opts === 'function') {
|
|
96
|
+
cb = opts;
|
|
97
|
+
// @ts-expect-error TS2322
|
|
98
|
+
opts = null;
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
cb(null, await fs.readdir(p, opts));
|
|
102
|
+
} catch (err) {
|
|
103
|
+
// @ts-expect-error TS2345
|
|
104
|
+
cb(err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
return (0, _fastGlob().default)((0, _path.normalizeSeparators)(p), options);
|
|
110
|
+
}
|
package/lib/hash.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hashFile = hashFile;
|
|
7
|
+
exports.hashObject = hashObject;
|
|
8
|
+
exports.hashStream = hashStream;
|
|
9
|
+
var _collection = require("./collection");
|
|
10
|
+
function _rust() {
|
|
11
|
+
const data = require("@atlaspack/rust");
|
|
12
|
+
_rust = function () {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
function hashStream(stream) {
|
|
18
|
+
let hash = new (_rust().Hash)();
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
stream.on('error', err => {
|
|
21
|
+
reject(err);
|
|
22
|
+
});
|
|
23
|
+
stream.on('data', chunk => {
|
|
24
|
+
hash.writeBuffer(chunk);
|
|
25
|
+
}).on('end', function () {
|
|
26
|
+
resolve(hash.finish());
|
|
27
|
+
}).on('error', err => {
|
|
28
|
+
reject(err);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function hashObject(obj) {
|
|
33
|
+
return (0, _rust().hashString)(JSON.stringify((0, _collection.objectSortedEntriesDeep)(obj)));
|
|
34
|
+
}
|
|
35
|
+
let testCache = {
|
|
36
|
+
/*:: ...null */
|
|
37
|
+
};
|
|
38
|
+
function hashFile(fs, filePath) {
|
|
39
|
+
if (process.env.ATLASPACK_BUILD_ENV === 'test') {
|
|
40
|
+
// Development builds of these native modules are especially big and slow to hash.
|
|
41
|
+
if (/parcel-swc\.[^\\/]+\.node$|lightningcss.[^\\/]+.node$/.test(filePath)) {
|
|
42
|
+
let cacheEntry = testCache[filePath];
|
|
43
|
+
if (cacheEntry) return cacheEntry;
|
|
44
|
+
let v = hashStream(fs.createReadStream(filePath));
|
|
45
|
+
testCache[filePath] = v;
|
|
46
|
+
return v;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return hashStream(fs.createReadStream(filePath));
|
|
50
|
+
}
|