@atlaspack/utils 2.16.1 → 2.16.2-noselfbuild-342bd6c75.0

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.
Files changed (46) hide show
  1. package/LICENSE +201 -0
  2. package/lib/DefaultMap.js +46 -0
  3. package/lib/Deferred.js +30 -0
  4. package/lib/PromiseQueue.js +112 -0
  5. package/lib/TapStream.js +34 -0
  6. package/lib/alternatives.js +116 -0
  7. package/lib/ansi-html.js +18 -0
  8. package/lib/blob.js +40 -0
  9. package/lib/bundle-url.js +34 -0
  10. package/lib/collection.js +111 -0
  11. package/lib/config.js +172 -0
  12. package/lib/countLines.js +15 -0
  13. package/lib/debounce.js +18 -0
  14. package/lib/debug-tools.js +36 -0
  15. package/lib/dependency-location.js +21 -0
  16. package/lib/escape-html.js +22 -0
  17. package/lib/generateBuildMetrics.js +121 -0
  18. package/lib/generateCertificate.js +129 -0
  19. package/lib/getCertificate.js +18 -0
  20. package/lib/getExisting.js +25 -0
  21. package/lib/getModuleParts.js +30 -0
  22. package/lib/getRootDir.js +52 -0
  23. package/lib/glob.js +110 -0
  24. package/lib/hash.js +50 -0
  25. package/lib/http-server.js +85 -0
  26. package/lib/index.js +478 -37346
  27. package/lib/is-url.js +22 -0
  28. package/lib/isDirectoryInside.js +18 -0
  29. package/lib/objectHash.js +27 -0
  30. package/lib/openInBrowser.js +74 -0
  31. package/lib/parseCSSImport.js +15 -0
  32. package/lib/path.js +39 -0
  33. package/lib/prettifyTime.js +9 -0
  34. package/lib/prettyDiagnostic.js +136 -0
  35. package/lib/progress-message.js +27 -0
  36. package/lib/relativeBundlePath.js +22 -0
  37. package/lib/relativeUrl.js +24 -0
  38. package/lib/replaceBundleReferences.js +199 -0
  39. package/lib/schema.js +336 -0
  40. package/lib/shared-buffer.js +27 -0
  41. package/lib/sourcemap.js +127 -0
  42. package/lib/stream.js +76 -0
  43. package/lib/throttle.js +15 -0
  44. package/lib/urlJoin.js +35 -0
  45. package/package.json +16 -16
  46. package/lib/index.js.map +0 -1
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.objectSortedEntries = objectSortedEntries;
7
+ exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
8
+ exports.setDifference = setDifference;
9
+ exports.setEqual = setEqual;
10
+ exports.setIntersect = setIntersect;
11
+ exports.setIntersectStatic = setIntersectStatic;
12
+ exports.setSymmetricDifference = setSymmetricDifference;
13
+ exports.setUnion = setUnion;
14
+ exports.unique = unique;
15
+ function unique(array) {
16
+ return [...new Set(array)];
17
+ }
18
+ function objectSortedEntries(obj) {
19
+ return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
20
+ }
21
+ function objectSortedEntriesDeep(object) {
22
+ let sortedEntries = objectSortedEntries(object);
23
+ for (let i = 0; i < sortedEntries.length; i++) {
24
+ sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
25
+ }
26
+ return sortedEntries;
27
+ }
28
+ function sortEntry(entry) {
29
+ if (Array.isArray(entry)) {
30
+ return entry.map(sortEntry);
31
+ }
32
+ if (typeof entry === 'object' && entry != null) {
33
+ return objectSortedEntriesDeep(entry);
34
+ }
35
+ return entry;
36
+ }
37
+
38
+ /**
39
+ * Get the difference of A and B sets
40
+ *
41
+ * This is the set of elements which are in A but not in B
42
+ * For example, the difference of the sets {1,2,3} and {3,4} is {1,2}
43
+ *
44
+ * @param {*} a Set A
45
+ * @param {*} b Set B
46
+ * @returns A \ B
47
+ */
48
+ function setDifference(a, b) {
49
+ let difference = new Set();
50
+ for (let e of a) {
51
+ if (!b.has(e)) {
52
+ difference.add(e);
53
+ }
54
+ }
55
+ return difference;
56
+ }
57
+
58
+ /**
59
+ * Get the symmetric difference of A and B sets
60
+ *
61
+ * This is the set of elements which are in either of the sets, but not in their intersection.
62
+ * For example, the symmetric difference of the sets {1,2,3} and {3,4} is {1,2,4}
63
+ *
64
+ * @param {*} a Set A
65
+ * @param {*} b Set B
66
+ * @returns A Δ B
67
+ */
68
+ function setSymmetricDifference(a, b) {
69
+ let difference = new Set();
70
+ for (let e of a) {
71
+ if (!b.has(e)) {
72
+ difference.add(e);
73
+ }
74
+ }
75
+ for (let d of b) {
76
+ if (!a.has(d)) {
77
+ difference.add(d);
78
+ }
79
+ }
80
+ return difference;
81
+ }
82
+ function setIntersect(a, b) {
83
+ for (let entry of a) {
84
+ if (!b.has(entry)) {
85
+ a.delete(entry);
86
+ }
87
+ }
88
+ }
89
+ function setIntersectStatic(a, b) {
90
+ let intersection = new Set();
91
+ for (let entry of a) {
92
+ if (b.has(entry)) {
93
+ intersection.add(entry);
94
+ }
95
+ }
96
+ return intersection;
97
+ }
98
+ function setUnion(a, b) {
99
+ return new Set([...a, ...b]);
100
+ }
101
+ function setEqual(a, b) {
102
+ if (a.size != b.size) {
103
+ return false;
104
+ }
105
+ for (let entry of a) {
106
+ if (!b.has(entry)) {
107
+ return false;
108
+ }
109
+ }
110
+ return true;
111
+ }
package/lib/config.js ADDED
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadConfig = loadConfig;
7
+ exports.readConfig = readConfig;
8
+ exports.resolveConfig = resolveConfig;
9
+ exports.resolveConfigSync = resolveConfigSync;
10
+ function _diagnostic() {
11
+ const data = _interopRequireDefault(require("@atlaspack/diagnostic"));
12
+ _diagnostic = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _path() {
18
+ const data = _interopRequireDefault(require("path"));
19
+ _path = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _clone() {
25
+ const data = _interopRequireDefault(require("clone"));
26
+ _clone = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _json() {
32
+ const data = _interopRequireDefault(require("json5"));
33
+ _json = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _toml() {
39
+ const data = require("@iarna/toml");
40
+ _toml = function () {
41
+ return data;
42
+ };
43
+ return data;
44
+ }
45
+ function _lruCache() {
46
+ const data = _interopRequireDefault(require("lru-cache"));
47
+ _lruCache = function () {
48
+ return data;
49
+ };
50
+ return data;
51
+ }
52
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
+ const configCache = new (_lruCache().default)({
54
+ max: 500
55
+ });
56
+ const resolveCache = new Map();
57
+ function resolveConfig(fs, filepath, filenames, projectRoot) {
58
+ // Cache the result of resolving config for this directory.
59
+ // This is automatically invalidated at the end of the current build.
60
+ let key = _path().default.dirname(filepath) + filenames.join(',');
61
+ let cached = resolveCache.get(key);
62
+ if (cached !== undefined) {
63
+ return Promise.resolve(cached);
64
+ }
65
+ let resolved = fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
66
+ resolveCache.set(key, resolved);
67
+ return Promise.resolve(resolved);
68
+ }
69
+ function resolveConfigSync(fs, filepath, filenames, projectRoot) {
70
+ return fs.findAncestorFile(filenames, _path().default.dirname(filepath), projectRoot);
71
+ }
72
+ async function loadConfig(fs, filepath, filenames, projectRoot, opts) {
73
+ let parse = (opts === null || opts === void 0 ? void 0 : opts.parse) ?? true;
74
+ let configFile = await resolveConfig(fs, filepath, filenames, projectRoot);
75
+ if (configFile) {
76
+ let cachedOutput = configCache.get(String(parse) + configFile);
77
+ if (cachedOutput) {
78
+ return cachedOutput;
79
+ }
80
+ try {
81
+ let extname = _path().default.extname(configFile).slice(1);
82
+ if (extname === 'js' || extname === 'cjs') {
83
+ let output = {
84
+ // $FlowFixMe
85
+ config: (0, _clone().default)(module.require(configFile)),
86
+ files: [{
87
+ filePath: configFile
88
+ }]
89
+ };
90
+ configCache.set(configFile, output);
91
+ return output;
92
+ }
93
+ return readConfig(fs, configFile, opts);
94
+ } catch (err) {
95
+ if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
96
+ return null;
97
+ }
98
+ throw err;
99
+ }
100
+ }
101
+ return null;
102
+ }
103
+ loadConfig.clear = () => {
104
+ configCache.reset();
105
+ resolveCache.clear();
106
+ };
107
+ async function readConfig(fs, configFile, opts) {
108
+ let parse = (opts === null || opts === void 0 ? void 0 : opts.parse) ?? true;
109
+ let cachedOutput = configCache.get(String(parse) + configFile);
110
+ if (cachedOutput) {
111
+ return cachedOutput;
112
+ }
113
+ try {
114
+ let configContent = await fs.readFile(configFile, 'utf8');
115
+ let config;
116
+ if (parse === false) {
117
+ config = configContent;
118
+ } else {
119
+ let extname = _path().default.extname(configFile).slice(1);
120
+ let parse = (opts === null || opts === void 0 ? void 0 : opts.parser) ?? getParser(extname);
121
+ try {
122
+ config = parse(configContent);
123
+ } catch (e) {
124
+ if (extname !== '' && extname !== 'json') {
125
+ throw e;
126
+ }
127
+ let pos = {
128
+ line: e.lineNumber,
129
+ column: e.columnNumber
130
+ };
131
+ throw new (_diagnostic().default)({
132
+ diagnostic: {
133
+ message: `Failed to parse ${_path().default.basename(configFile)}`,
134
+ origin: '@atlaspack/utils',
135
+ codeFrames: [{
136
+ language: 'json5',
137
+ filePath: configFile,
138
+ code: configContent,
139
+ codeHighlights: [{
140
+ start: pos,
141
+ end: pos,
142
+ message: e.message
143
+ }]
144
+ }]
145
+ }
146
+ });
147
+ }
148
+ }
149
+ let output = {
150
+ config,
151
+ files: [{
152
+ filePath: configFile
153
+ }]
154
+ };
155
+ configCache.set(String(parse) + configFile, output);
156
+ return output;
157
+ } catch (err) {
158
+ if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
159
+ return null;
160
+ }
161
+ throw err;
162
+ }
163
+ }
164
+ function getParser(extname) {
165
+ switch (extname) {
166
+ case 'toml':
167
+ return _toml().parse;
168
+ case 'json':
169
+ default:
170
+ return _json().default.parse;
171
+ }
172
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = countLines;
7
+ function countLines(string, startIndex = 0) {
8
+ let lines = 1;
9
+ for (let i = startIndex; i < string.length; i++) {
10
+ if (string.charAt(i) === '\n') {
11
+ lines++;
12
+ }
13
+ }
14
+ return lines;
15
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = debounce;
7
+ function debounce(fn, delay) {
8
+ let timeout;
9
+ return function (...args) {
10
+ if (timeout) {
11
+ clearTimeout(timeout);
12
+ }
13
+ timeout = setTimeout(() => {
14
+ timeout = null;
15
+ fn(...args);
16
+ }, delay);
17
+ };
18
+ }
@@ -0,0 +1,36 @@
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
+ let debugTools = exports.debugTools = {
18
+ 'asset-file-names-in-output': false,
19
+ 'simple-cli-reporter': false
20
+ };
21
+ const envVarValue = process.env.ATLASPACK_DEBUG_TOOLS ?? '';
22
+ for (let tool of envVarValue.split(',')) {
23
+ tool = tool.trim();
24
+ if (tool === 'all') {
25
+ for (let key in debugTools) {
26
+ debugTools[key] = true;
27
+ }
28
+ break;
29
+ } else if (debugTools.hasOwnProperty(tool)) {
30
+ debugTools[tool] = true;
31
+ } else if (tool === '') {
32
+ continue;
33
+ } else {
34
+ throw new Error(`Invalid debug tool option: ${tool}. Valid options are: ${Object.keys(debugTools).join(', ')}`);
35
+ }
36
+ }
@@ -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
+ '&': '&amp;',
12
+ '<': '&lt;',
13
+ '>': '&gt;',
14
+ '"': '&quot;',
15
+ "'": '&#39;'
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
+ }