@parcel/utils 2.0.0-nightly.146 → 2.0.0-nightly.1470

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 (105) hide show
  1. package/.eslintrc.js +6 -6
  2. package/lib/index.js +37542 -318
  3. package/lib/index.js.map +1 -0
  4. package/package.json +47 -20
  5. package/src/DefaultMap.js +1 -1
  6. package/src/PromiseQueue.js +16 -12
  7. package/src/alternatives.js +145 -0
  8. package/src/ansi-html.js +2 -2
  9. package/src/blob.js +2 -1
  10. package/src/bundle-url.js +1 -1
  11. package/src/collection.js +35 -15
  12. package/src/config.js +132 -45
  13. package/src/countLines.js +5 -2
  14. package/src/debounce.js +1 -1
  15. package/src/dependency-location.js +11 -6
  16. package/src/generateBuildMetrics.js +158 -0
  17. package/src/generateCertificate.js +1 -1
  18. package/src/getCertificate.js +1 -1
  19. package/src/getExisting.js +1 -4
  20. package/src/getModuleParts.js +23 -0
  21. package/src/getRootDir.js +1 -2
  22. package/src/glob.js +51 -10
  23. package/src/hash.js +49 -0
  24. package/src/http-server.js +29 -19
  25. package/src/index.js +68 -22
  26. package/src/is-url.js +1 -1
  27. package/src/isDirectoryInside.js +11 -0
  28. package/src/openInBrowser.js +64 -0
  29. package/src/path.js +38 -6
  30. package/src/prettyDiagnostic.js +102 -30
  31. package/src/progress-message.js +22 -0
  32. package/src/relativeBundlePath.js +8 -13
  33. package/src/replaceBundleReferences.js +85 -41
  34. package/src/schema.js +100 -44
  35. package/src/shared-buffer.js +23 -0
  36. package/src/sourcemap.js +138 -0
  37. package/src/stream.js +31 -1
  38. package/src/urlJoin.js +3 -1
  39. package/test/DefaultMap.test.js +7 -4
  40. package/test/collection.test.js +13 -1
  41. package/test/config.test.js +98 -0
  42. package/test/input/config/.testrc +3 -0
  43. package/test/input/config/config.cjs +3 -0
  44. package/test/input/config/config.js +3 -0
  45. package/test/input/config/config.json +3 -0
  46. package/test/input/config/empty.json +0 -0
  47. package/test/input/config/empty.toml +0 -0
  48. package/test/input/sourcemap/referenced-min.js +2 -0
  49. package/test/input/sourcemap/referenced-min.js.map +6 -0
  50. package/test/input/sourcemap/source-root.js +2 -0
  51. package/test/input/sourcemap/source-root.js.map +7 -0
  52. package/test/replaceBundleReferences.test.js +268 -0
  53. package/test/sourcemap.test.js +207 -0
  54. package/test/throttle.test.js +1 -2
  55. package/test/urlJoin.test.js +37 -0
  56. package/lib/DefaultMap.js +0 -64
  57. package/lib/Deferred.js +0 -26
  58. package/lib/PromiseQueue.js +0 -133
  59. package/lib/TapStream.js +0 -41
  60. package/lib/ansi-html.js +0 -16
  61. package/lib/blob.js +0 -31
  62. package/lib/bundle-url.js +0 -43
  63. package/lib/collection.js +0 -62
  64. package/lib/config.js +0 -88
  65. package/lib/countLines.js +0 -18
  66. package/lib/debounce.js +0 -20
  67. package/lib/dependency-location.js +0 -21
  68. package/lib/escape-html.js +0 -24
  69. package/lib/escape-markdown.js +0 -15
  70. package/lib/generateBundleReport.js +0 -38
  71. package/lib/generateCertificate.js +0 -124
  72. package/lib/getCertificate.js +0 -19
  73. package/lib/getExisting.js +0 -23
  74. package/lib/getRootDir.js +0 -55
  75. package/lib/glob.js +0 -76
  76. package/lib/http-server.js +0 -64
  77. package/lib/is-url.js +0 -17
  78. package/lib/loadSourceMapUrl.js +0 -33
  79. package/lib/md5.js +0 -35
  80. package/lib/objectHash.js +0 -26
  81. package/lib/parseCSSImport.js +0 -16
  82. package/lib/path.js +0 -22
  83. package/lib/prettifyTime.js +0 -10
  84. package/lib/prettyDiagnostic.js +0 -57
  85. package/lib/promisify.js +0 -13
  86. package/lib/relativeBundlePath.js +0 -24
  87. package/lib/relativeUrl.js +0 -16
  88. package/lib/replaceBundleReferences.js +0 -151
  89. package/lib/resolve.js +0 -93
  90. package/lib/schema.js +0 -320
  91. package/lib/serializeObject.js +0 -28
  92. package/lib/stream.js +0 -51
  93. package/lib/throttle.js +0 -16
  94. package/lib/urlJoin.js +0 -27
  95. package/src/.babelrc +0 -3
  96. package/src/escape-markdown.js +0 -10
  97. package/src/generateBundleReport.js +0 -51
  98. package/src/loadSourceMapUrl.js +0 -33
  99. package/src/md5.js +0 -44
  100. package/src/promisify.js +0 -13
  101. package/src/resolve.js +0 -135
  102. package/src/serializeObject.js +0 -22
  103. package/test/escapeMarkdown.test.js +0 -29
  104. package/test/input/sourcemap/referenced.js +0 -7
  105. package/test/loadSourceMapUrl.test.js +0 -37
@@ -1,133 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _Deferred = require("./Deferred");
9
-
10
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
-
12
- class PromiseQueue {
13
- constructor(opts = {
14
- maxConcurrent: Infinity
15
- }) {
16
- _defineProperty(this, "_deferred", void 0);
17
-
18
- _defineProperty(this, "_maxConcurrent", void 0);
19
-
20
- _defineProperty(this, "_numRunning", 0);
21
-
22
- _defineProperty(this, "_queue", []);
23
-
24
- _defineProperty(this, "_runPromise", null);
25
-
26
- _defineProperty(this, "_count", 0);
27
-
28
- _defineProperty(this, "_results", []);
29
-
30
- if (opts.maxConcurrent <= 0) {
31
- throw new TypeError('maxConcurrent must be a positive, non-zero value');
32
- }
33
-
34
- this._maxConcurrent = opts.maxConcurrent;
35
- }
36
-
37
- getNumWaiting() {
38
- return this._queue.length;
39
- }
40
-
41
- add(fn) {
42
- return new Promise((resolve, reject) => {
43
- let i = this._count++;
44
-
45
- this._queue.push(() => fn().then(result => {
46
- this._results[i] = result;
47
- resolve(result);
48
- }, err => {
49
- reject(err);
50
- throw err;
51
- }));
52
-
53
- if (this._numRunning > 0 && this._numRunning < this._maxConcurrent) {
54
- this._next();
55
- }
56
- });
57
- }
58
-
59
- run() {
60
- if (this._runPromise != null) {
61
- return this._runPromise;
62
- }
63
-
64
- if (this._queue.length === 0) {
65
- return Promise.resolve([]);
66
- }
67
-
68
- let {
69
- deferred,
70
- promise
71
- } = (0, _Deferred.makeDeferredWithPromise)();
72
- this._deferred = deferred;
73
- this._runPromise = promise;
74
-
75
- while (this._queue.length && this._numRunning < this._maxConcurrent) {
76
- this._next();
77
- }
78
-
79
- return promise;
80
- }
81
-
82
- async _next() {
83
- let fn = this._queue.shift();
84
-
85
- await this._runFn(fn);
86
-
87
- if (this._queue.length) {
88
- this._next();
89
- } else if (this._numRunning === 0) {
90
- this._resolve();
91
- }
92
- }
93
-
94
- async _runFn(fn) {
95
- this._numRunning++;
96
-
97
- try {
98
- await fn();
99
- this._numRunning--;
100
- } catch (e) {
101
- this._reject(e); // rejecting resets state so numRunning is reset to 0 here
102
-
103
- }
104
- }
105
-
106
- _resetState() {
107
- this._queue = [];
108
- this._count = 0;
109
- this._results = [];
110
- this._runPromise = null;
111
- this._numRunning = 0;
112
- this._deferred = null;
113
- }
114
-
115
- _reject(err) {
116
- if (this._deferred != null) {
117
- this._deferred.reject(err);
118
- }
119
-
120
- this._resetState();
121
- }
122
-
123
- _resolve() {
124
- if (this._deferred != null) {
125
- this._deferred.resolve(this._results);
126
- }
127
-
128
- this._resetState();
129
- }
130
-
131
- }
132
-
133
- exports.default = PromiseQueue;
package/lib/TapStream.js DELETED
@@ -1,41 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _stream = require("stream");
9
-
10
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
11
-
12
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
-
14
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
16
- /*
17
- * "Taps" into the contents of a flowing stream, yielding chunks to the passed
18
- * callback. Continues to pass data chunks down the stream.
19
- */
20
- class TapStream extends _stream.Transform {
21
- constructor(tap, options) {
22
- super(_objectSpread({}, options));
23
-
24
- _defineProperty(this, "_tap", void 0);
25
-
26
- this._tap = tap;
27
- }
28
-
29
- _transform(chunk, encoding, callback) {
30
- try {
31
- this._tap(Buffer.from(chunk));
32
-
33
- callback(null, chunk);
34
- } catch (err) {
35
- callback(err);
36
- }
37
- }
38
-
39
- }
40
-
41
- exports.default = TapStream;
package/lib/ansi-html.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.ansiHtml = ansiHtml;
7
-
8
- var _ansiHtml = _interopRequireDefault(require("ansi-html"));
9
-
10
- var _escapeHtml = require("./escape-html");
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- function ansiHtml(ansi) {
15
- return (0, _ansiHtml.default)((0, _escapeHtml.escapeHTML)(ansi));
16
- }
package/lib/blob.js DELETED
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.blobToBuffer = blobToBuffer;
7
- exports.blobToString = blobToString;
8
-
9
- var _ = require("../");
10
-
11
- var _stream = require("stream");
12
-
13
- function blobToBuffer(blob) {
14
- if (blob instanceof _stream.Readable) {
15
- return (0, _.bufferStream)(blob);
16
- } else if (blob instanceof Buffer) {
17
- return Promise.resolve(Buffer.from(blob));
18
- } else {
19
- return Promise.resolve(Buffer.from(blob, 'utf8'));
20
- }
21
- }
22
-
23
- async function blobToString(blob) {
24
- if (blob instanceof _stream.Readable) {
25
- return (await (0, _.bufferStream)(blob)).toString();
26
- } else if (blob instanceof Buffer) {
27
- return blob.toString();
28
- } else {
29
- return blob;
30
- }
31
- }
package/lib/bundle-url.js DELETED
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getBaseURL = getBaseURL;
7
- exports.getBundleURL = void 0;
8
- let bundleURL = null;
9
-
10
- function getBundleURLCached() {
11
- if (bundleURL == null) {
12
- bundleURL = _getBundleURL();
13
- }
14
-
15
- return bundleURL;
16
- }
17
-
18
- function _getBundleURL() {
19
- // Attempt to find the URL of the current script and use that as the base URL
20
- try {
21
- throw new Error();
22
- } catch (err) {
23
- let stack = typeof err.stack === 'string' ? err.stack : '';
24
- let matches = stack.match(/(https?|file|ftp):\/\/[^)\n]+/g);
25
-
26
- if (matches) {
27
- return getBaseURL(matches[0]);
28
- }
29
- }
30
-
31
- return '/';
32
- }
33
-
34
- function getBaseURL(url) {
35
- if (url == null) {
36
- return '/';
37
- }
38
-
39
- return url.replace(/^((?:https?|file|ftp):\/\/.+)\/[^/]+$/, '$1') + '/';
40
- }
41
-
42
- const getBundleURL = getBundleURLCached;
43
- exports.getBundleURL = getBundleURL;
package/lib/collection.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.unique = unique;
7
- exports.flatMap = flatMap;
8
- exports.objectSortedEntries = objectSortedEntries;
9
- exports.objectSortedEntriesDeep = objectSortedEntriesDeep;
10
- exports.setDifference = setDifference;
11
-
12
- function unique(array) {
13
- return [...new Set(array)];
14
- }
15
-
16
- function flatMap(array, projectFn) {
17
- let out = [];
18
-
19
- for (let arr of array.map(projectFn)) {
20
- out.push(...arr);
21
- }
22
-
23
- return out;
24
- }
25
-
26
- function objectSortedEntries(obj) {
27
- return Object.entries(obj).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
28
- }
29
-
30
- function objectSortedEntriesDeep(object) {
31
- let sortedEntries = objectSortedEntries(object);
32
-
33
- for (let i = 0; i < sortedEntries.length; i++) {
34
- sortedEntries[i][1] = sortEntry(sortedEntries[i][1]);
35
- }
36
-
37
- return sortedEntries;
38
- }
39
-
40
- function sortEntry(entry) {
41
- if (Array.isArray(entry)) {
42
- return entry.map(sortEntry);
43
- }
44
-
45
- if (typeof entry === 'object' && entry != null) {
46
- return objectSortedEntriesDeep(entry);
47
- }
48
-
49
- return entry;
50
- }
51
-
52
- function setDifference(a, b) {
53
- let difference = new Set();
54
-
55
- for (let e of a) {
56
- if (!b.has(e)) {
57
- difference.add(e);
58
- }
59
- }
60
-
61
- return difference;
62
- }
package/lib/config.js DELETED
@@ -1,88 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.resolveConfig = resolveConfig;
7
- exports.loadConfig = loadConfig;
8
-
9
- var _path = _interopRequireDefault(require("path"));
10
-
11
- var _clone = _interopRequireDefault(require("clone"));
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- const PARSERS = {
16
- json: require('json5').parse,
17
- toml: require('@iarna/toml').parse
18
- };
19
- const existsCache = new Map();
20
-
21
- async function resolveConfig(fs, filepath, filenames, opts, root = _path.default.parse(filepath).root) {
22
- filepath = await fs.realpath(_path.default.dirname(filepath)); // Don't traverse above the module root
23
-
24
- if (filepath === root || _path.default.basename(filepath) === 'node_modules') {
25
- return null;
26
- }
27
-
28
- for (const filename of filenames) {
29
- let file = _path.default.join(filepath, filename);
30
-
31
- if ((await fs.exists(file)) && (await fs.stat(file)).isFile()) {
32
- return file;
33
- }
34
- }
35
-
36
- return resolveConfig(fs, filepath, filenames, opts);
37
- }
38
-
39
- async function loadConfig(fs, filepath, filenames, opts) {
40
- let configFile = await resolveConfig(fs, filepath, filenames, opts);
41
-
42
- if (configFile) {
43
- try {
44
- let extname = _path.default.extname(configFile).slice(1);
45
-
46
- if (extname === 'js') {
47
- return {
48
- // $FlowFixMe
49
- config: (0, _clone.default)(require(configFile)),
50
- files: [{
51
- filePath: configFile
52
- }]
53
- };
54
- }
55
-
56
- let configContent = await fs.readFile(configFile, 'utf8');
57
-
58
- if (!configContent) {
59
- return null;
60
- }
61
-
62
- let config;
63
-
64
- if (opts && opts.parse === false) {
65
- config = configContent;
66
- } else {
67
- let parse = PARSERS[extname] || PARSERS.json;
68
- config = parse(configContent);
69
- }
70
-
71
- return {
72
- config: config,
73
- files: [{
74
- filePath: configFile
75
- }]
76
- };
77
- } catch (err) {
78
- if (err.code === 'MODULE_NOT_FOUND' || err.code === 'ENOENT') {
79
- existsCache.delete(configFile);
80
- return null;
81
- }
82
-
83
- throw err;
84
- }
85
- }
86
-
87
- return null;
88
- }
package/lib/countLines.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = countLines;
7
-
8
- function countLines(string) {
9
- let lines = 1;
10
-
11
- for (let i = 0; i < string.length; i++) {
12
- if (string.charAt(i) === '\n') {
13
- lines++;
14
- }
15
- }
16
-
17
- return lines;
18
- }
package/lib/debounce.js DELETED
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = debounce;
7
-
8
- function debounce(fn, delay) {
9
- let timeout;
10
- return function (...args) {
11
- if (timeout) {
12
- clearTimeout(timeout);
13
- }
14
-
15
- timeout = setTimeout(() => {
16
- timeout = null;
17
- fn(...args);
18
- }, delay);
19
- };
20
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = createDependencyLocation;
7
-
8
- function createDependencyLocation(start, moduleSpecifier, lineOffset = 0, columnOffset = 0, // Imports are usually wrapped in quotes
9
- importWrapperLength = 2) {
10
- return {
11
- filePath: moduleSpecifier,
12
- start: {
13
- line: start.line + lineOffset,
14
- column: start.column + columnOffset
15
- },
16
- end: {
17
- line: start.line + lineOffset,
18
- column: start.column + moduleSpecifier.length - 1 + importWrapperLength + columnOffset
19
- }
20
- };
21
- }
@@ -1,24 +0,0 @@
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
-
18
- function escapeHTML(s) {
19
- if (reHasUnescapedHtml.test(s)) {
20
- return s.replace(reUnescapedHtml, c => htmlEscapes[c]);
21
- }
22
-
23
- return s;
24
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.escapeMarkdown = escapeMarkdown;
7
- const escapeCharacters = ['\\', '*', '_', '~'];
8
-
9
- function escapeMarkdown(s) {
10
- for (const char of escapeCharacters) {
11
- s = s.replace(new RegExp(`\\${char}`, 'g'), `\\${char}`);
12
- }
13
-
14
- return s;
15
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = generateBundleReport;
7
-
8
- var _nullthrows = _interopRequireDefault(require("nullthrows"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- function generateBundleReport(bundleGraph, largestAssetCount = 10) {
13
- let bundles = [];
14
- bundleGraph.traverseBundles(bundle => {
15
- bundles.push(bundle);
16
- });
17
- bundles.sort((a, b) => b.stats.size - a.stats.size);
18
- return {
19
- bundles: bundles.map(bundle => {
20
- let assets = [];
21
- bundle.traverseAssets(asset => {
22
- assets.push(asset);
23
- });
24
- assets.sort((a, b) => b.stats.size - a.stats.size);
25
- return {
26
- filePath: (0, _nullthrows.default)(bundle.filePath),
27
- size: bundle.stats.size,
28
- time: bundle.stats.time,
29
- largestAssets: assets.slice(0, largestAssetCount).map(asset => ({
30
- filePath: asset.filePath,
31
- size: asset.stats.size,
32
- time: asset.stats.time
33
- })),
34
- totalAssets: assets.length
35
- };
36
- })
37
- };
38
- }
@@ -1,124 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = generateCertificate;
7
-
8
- var _nodeForge = _interopRequireDefault(require("node-forge"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _logger = _interopRequireDefault(require("@parcel/logger"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- async function generateCertificate(fs, cacheDir, host) {
17
- let certDirectory = cacheDir;
18
-
19
- const privateKeyPath = _path.default.join(certDirectory, 'private.pem');
20
-
21
- const certPath = _path.default.join(certDirectory, 'primary.crt');
22
-
23
- const cachedKey = (await fs.exists(privateKeyPath)) && (await fs.readFile(privateKeyPath));
24
- const cachedCert = (await fs.exists(certPath)) && (await fs.readFile(certPath));
25
-
26
- if (cachedKey && cachedCert) {
27
- return {
28
- key: cachedKey,
29
- cert: cachedCert
30
- };
31
- }
32
-
33
- _logger.default.progress('Generating SSL Certificate...');
34
-
35
- const pki = _nodeForge.default.pki;
36
- const keys = pki.rsa.generateKeyPair(2048);
37
- const cert = pki.createCertificate();
38
- cert.publicKey = keys.publicKey;
39
- cert.serialNumber = Date.now().toString();
40
- cert.validity.notBefore = new Date();
41
- cert.validity.notAfter = new Date();
42
- cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
43
- const attrs = [{
44
- name: 'commonName',
45
- value: 'parceljs.org'
46
- }, {
47
- name: 'countryName',
48
- value: 'US'
49
- }, {
50
- shortName: 'ST',
51
- value: 'Virginia'
52
- }, {
53
- name: 'localityName',
54
- value: 'Blacksburg'
55
- }, {
56
- name: 'organizationName',
57
- value: 'parcelBundler'
58
- }, {
59
- shortName: 'OU',
60
- value: 'Test'
61
- }];
62
- let altNames = [{
63
- type: 2,
64
- // DNS
65
- value: 'localhost'
66
- }, {
67
- type: 7,
68
- // IP
69
- ip: '127.0.0.1'
70
- }];
71
-
72
- if (host) {
73
- altNames.push({
74
- type: 2,
75
- // DNS
76
- value: host
77
- });
78
- }
79
-
80
- cert.setSubject(attrs);
81
- cert.setIssuer(attrs);
82
- cert.setExtensions([{
83
- name: 'basicConstraints',
84
- cA: false
85
- }, {
86
- name: 'keyUsage',
87
- keyCertSign: true,
88
- digitalSignature: true,
89
- nonRepudiation: true,
90
- keyEncipherment: true,
91
- dataEncipherment: true
92
- }, {
93
- name: 'extKeyUsage',
94
- serverAuth: true,
95
- clientAuth: true,
96
- codeSigning: true,
97
- emailProtection: true,
98
- timeStamping: true
99
- }, {
100
- name: 'nsCertType',
101
- client: true,
102
- server: true,
103
- email: true,
104
- objsign: true,
105
- sslCA: true,
106
- emailCA: true,
107
- objCA: true
108
- }, {
109
- name: 'subjectAltName',
110
- altNames
111
- }, {
112
- name: 'subjectKeyIdentifier'
113
- }]);
114
- cert.sign(keys.privateKey, _nodeForge.default.md.sha256.create());
115
- const privPem = pki.privateKeyToPem(keys.privateKey);
116
- const certPem = pki.certificateToPem(cert);
117
- await fs.mkdirp(certDirectory);
118
- await fs.writeFile(privateKeyPath, privPem);
119
- await fs.writeFile(certPath, certPem);
120
- return {
121
- key: privPem,
122
- cert: certPem
123
- };
124
- }
@@ -1,19 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = getCertificate;
7
-
8
- async function getCertificate(fs, options) {
9
- try {
10
- let cert = await fs.readFile(options.cert);
11
- let key = await fs.readFile(options.key);
12
- return {
13
- key,
14
- cert
15
- };
16
- } catch (err) {
17
- throw new Error('Certificate and/or key not found');
18
- }
19
- }