@atlaspack/utils 2.16.2-noselfbuild-3f2849b52.0 → 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 (45) hide show
  1. package/lib/DefaultMap.js +46 -0
  2. package/lib/Deferred.js +30 -0
  3. package/lib/PromiseQueue.js +112 -0
  4. package/lib/TapStream.js +34 -0
  5. package/lib/alternatives.js +116 -0
  6. package/lib/ansi-html.js +18 -0
  7. package/lib/blob.js +40 -0
  8. package/lib/bundle-url.js +34 -0
  9. package/lib/collection.js +111 -0
  10. package/lib/config.js +172 -0
  11. package/lib/countLines.js +15 -0
  12. package/lib/debounce.js +18 -0
  13. package/lib/debug-tools.js +36 -0
  14. package/lib/dependency-location.js +21 -0
  15. package/lib/escape-html.js +22 -0
  16. package/lib/generateBuildMetrics.js +121 -0
  17. package/lib/generateCertificate.js +129 -0
  18. package/lib/getCertificate.js +18 -0
  19. package/lib/getExisting.js +25 -0
  20. package/lib/getModuleParts.js +30 -0
  21. package/lib/getRootDir.js +52 -0
  22. package/lib/glob.js +110 -0
  23. package/lib/hash.js +50 -0
  24. package/lib/http-server.js +85 -0
  25. package/lib/index.js +478 -37357
  26. package/lib/is-url.js +22 -0
  27. package/lib/isDirectoryInside.js +18 -0
  28. package/lib/objectHash.js +27 -0
  29. package/lib/openInBrowser.js +74 -0
  30. package/lib/parseCSSImport.js +15 -0
  31. package/lib/path.js +39 -0
  32. package/lib/prettifyTime.js +9 -0
  33. package/lib/prettyDiagnostic.js +136 -0
  34. package/lib/progress-message.js +27 -0
  35. package/lib/relativeBundlePath.js +22 -0
  36. package/lib/relativeUrl.js +24 -0
  37. package/lib/replaceBundleReferences.js +199 -0
  38. package/lib/schema.js +336 -0
  39. package/lib/shared-buffer.js +27 -0
  40. package/lib/sourcemap.js +127 -0
  41. package/lib/stream.js +76 -0
  42. package/lib/throttle.js +15 -0
  43. package/lib/urlJoin.js +35 -0
  44. package/package.json +15 -16
  45. package/lib/index.js.map +0 -1
package/lib/is-url.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isURL;
7
+ function _isUrl() {
8
+ const data = _interopRequireDefault(require("is-url"));
9
+ _isUrl = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ // Matches anchor (ie: #raptors)
16
+ const ANCHOR_REGEXP = /^#/;
17
+
18
+ // Matches scheme (ie: tel:, mailto:, data:, itms-apps:)
19
+ const SCHEME_REGEXP = /^[a-z][a-z0-9\-+.]*:/i;
20
+ function isURL(url) {
21
+ return (0, _isUrl().default)(url) || ANCHOR_REGEXP.test(url) || SCHEME_REGEXP.test(url);
22
+ }
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = isDirectoryInside;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function isDirectoryInside(child, parent) {
16
+ const relative = _path().default.relative(parent, child);
17
+ return !relative.startsWith('..') && !_path().default.isAbsolute(relative);
18
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = objectHash;
7
+ function _crypto() {
8
+ const data = _interopRequireDefault(require("crypto"));
9
+ _crypto = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ // $FlowFixMe
16
+ function objectHash(object) {
17
+ let hash = _crypto().default.createHash('md5');
18
+ for (let key of Object.keys(object).sort()) {
19
+ let val = object[key];
20
+ if (typeof val === 'object' && val) {
21
+ hash.update(key + objectHash(val));
22
+ } else {
23
+ hash.update(key + val);
24
+ }
25
+ }
26
+ return hash.digest('hex');
27
+ }
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = openInBrowser;
7
+ function _open() {
8
+ const data = _interopRequireDefault(require("open"));
9
+ _open = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _child_process() {
15
+ const data = require("child_process");
16
+ _child_process = 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
+ // Chrome app name is platform dependent. we should not hard code it.
30
+ // https://github.com/react-native-community/cli/blob/e2be8a905285d9b37512fc78c9755b9635ecf805/packages/cli/src/commands/server/launchDebugger.ts#L28
31
+ function getChromeAppName() {
32
+ switch (process.platform) {
33
+ case 'darwin':
34
+ return 'google chrome';
35
+ case 'win32':
36
+ return 'chrome';
37
+ case 'linux':
38
+ if (commandExistsUnixSync('google-chrome')) {
39
+ return 'google-chrome';
40
+ }
41
+ if (commandExistsUnixSync('chromium-browser')) {
42
+ return 'chromium-browser';
43
+ }
44
+ return 'chromium';
45
+ default:
46
+ return 'google-chrome';
47
+ }
48
+ }
49
+ function commandExistsUnixSync(commandName) {
50
+ try {
51
+ const stdout = (0, _child_process().execSync)(`command -v ${commandName} 2>/dev/null` + ` && { echo >&1 '${commandName} found'; exit 0; }`);
52
+ return !!stdout;
53
+ } catch (error) {
54
+ return false;
55
+ }
56
+ }
57
+ function getAppName(appName) {
58
+ if (['google', 'chrome'].includes(appName)) {
59
+ return getChromeAppName();
60
+ } else if (['brave', 'Brave'].includes(appName)) {
61
+ return 'Brave Browser';
62
+ } else return appName;
63
+ }
64
+ async function openInBrowser(url, browser) {
65
+ try {
66
+ const options = typeof browser === 'string' && browser.length > 0 ? {
67
+ app: [getAppName(browser)]
68
+ } : undefined;
69
+ await (0, _open().default)(url, options);
70
+ } catch (err) {
71
+ _logger().default.error(`Unexpected error while opening in browser: ${browser}`, '@atlaspack/utils');
72
+ _logger().default.error(err, '@atlaspack/utils');
73
+ }
74
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = parseCSSImport;
7
+ function parseCSSImport(url) {
8
+ if (!/^(~|\.\/|\/)/.test(url)) {
9
+ return './' + url;
10
+ } else if (!/^(~\/|\.\/|\/)/.test(url)) {
11
+ return url.substring(1);
12
+ } else {
13
+ return url;
14
+ }
15
+ }
package/lib/path.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isAbsolute = isAbsolute;
7
+ exports.normalizePath = normalizePath;
8
+ exports.normalizeSeparators = normalizeSeparators;
9
+ exports.relativePath = relativePath;
10
+ function _path() {
11
+ const data = _interopRequireDefault(require("path"));
12
+ _path = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:){0,1}[\\/]+/;
19
+ const SEPARATOR_REGEX = /[\\]+/g;
20
+ function isAbsolute(filepath) {
21
+ return ABSOLUTE_PATH_REGEX.test(filepath);
22
+ }
23
+ function normalizeSeparators(filePath) {
24
+ return filePath.replace(SEPARATOR_REGEX, '/');
25
+ }
26
+ function normalizePath(filePath, leadingDotSlash = true) {
27
+ if (leadingDotSlash && (filePath[0] !== '.' || filePath[1] !== '.' && filePath[1] !== '/' && filePath[1] !== '\\') && !_path().default.isAbsolute(filePath)) {
28
+ return normalizeSeparators('./' + filePath);
29
+ } else {
30
+ return normalizeSeparators(filePath);
31
+ }
32
+ }
33
+ function relativePath(from, to, leadingDotSlash = true) {
34
+ // Fast path
35
+ if (to.startsWith(from + '/')) {
36
+ return (leadingDotSlash ? './' : '') + to.slice(from.length + 1);
37
+ }
38
+ return normalizePath(_path().default.relative(from, to), leadingDotSlash);
39
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = prettifyTime;
7
+ function prettifyTime(timeInMs) {
8
+ return timeInMs < 1000 ? `${timeInMs}ms` : `${(timeInMs / 1000).toFixed(2)}s`;
9
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = prettyDiagnostic;
7
+ function _codeframe() {
8
+ const data = _interopRequireDefault(require("@atlaspack/codeframe"));
9
+ _codeframe = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _markdownAnsi() {
15
+ const data = _interopRequireDefault(require("@atlaspack/markdown-ansi"));
16
+ _markdownAnsi = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _chalk2() {
22
+ const data = _interopRequireDefault(require("chalk"));
23
+ _chalk2 = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ function _path() {
29
+ const data = _interopRequireDefault(require("path"));
30
+ _path = function () {
31
+ return data;
32
+ };
33
+ return data;
34
+ }
35
+ function _terminalLink2() {
36
+ const data = _interopRequireDefault(require("terminal-link"));
37
+ _terminalLink2 = function () {
38
+ return data;
39
+ };
40
+ return data;
41
+ }
42
+ function _snarkdown() {
43
+ const data = _interopRequireDefault(require("snarkdown"));
44
+ _snarkdown = function () {
45
+ return data;
46
+ };
47
+ return data;
48
+ }
49
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
50
+ // $FlowFixMe
51
+ /* eslint-disable import/no-extraneous-dependencies */
52
+ // $FlowFixMe
53
+ /* eslint-enable import/no-extraneous-dependencies */
54
+ async function prettyDiagnostic(diagnostic, options, terminalWidth, format = 'ansi') {
55
+ let {
56
+ origin,
57
+ message,
58
+ stack,
59
+ codeFrames,
60
+ hints,
61
+ skipFormatting,
62
+ documentationURL
63
+ } = diagnostic;
64
+ const md = format === 'ansi' ? _markdownAnsi().default : _snarkdown().default;
65
+ const terminalLink = format === 'ansi' ? _terminalLink2().default :
66
+ // eslint-disable-next-line no-unused-vars
67
+ (text, url, _) => `<a href="${url}">${text}</a>`;
68
+ const chalk = format === 'ansi' ? _chalk2().default : {
69
+ gray: {
70
+ underline: v => `<span style="color: grey; text-decoration: underline;">${v}</span>`
71
+ }
72
+ };
73
+ let result = {
74
+ message: md(`**${origin ?? 'unknown'}**: `) + (skipFormatting ? message : md(message)),
75
+ stack: '',
76
+ codeframe: '',
77
+ frames: [],
78
+ hints: [],
79
+ documentation: ''
80
+ };
81
+ if (codeFrames != null) {
82
+ for (let codeFrame of codeFrames) {
83
+ let filePath = codeFrame.filePath;
84
+ if (filePath != null && options && !_path().default.isAbsolute(filePath)) {
85
+ filePath = _path().default.join(options.projectRoot, filePath);
86
+ }
87
+ let highlights = codeFrame.codeHighlights;
88
+ let code = codeFrame.code;
89
+ if (code == null && options && filePath != null) {
90
+ code = await options.inputFS.readFile(filePath, 'utf8');
91
+ }
92
+ let formattedCodeFrame = '';
93
+ if (code != null) {
94
+ formattedCodeFrame = (0, _codeframe().default)(code, highlights, {
95
+ useColor: true,
96
+ syntaxHighlighting: true,
97
+ language:
98
+ // $FlowFixMe sketchy null checks do not matter here...
99
+ codeFrame.language || (filePath != null ? _path().default.extname(filePath).substr(1) : undefined),
100
+ terminalWidth
101
+ });
102
+ }
103
+ let location;
104
+ if (typeof filePath !== 'string') {
105
+ location = '';
106
+ } else if (highlights.length === 0) {
107
+ location = filePath;
108
+ } else {
109
+ location = `${filePath}:${highlights[0].start.line}:${highlights[0].start.column}`;
110
+ }
111
+ result.codeframe += location ? chalk.gray.underline(location) + '\n' : '';
112
+ result.codeframe += formattedCodeFrame;
113
+ if (codeFrame !== codeFrames[codeFrames.length - 1]) {
114
+ result.codeframe += '\n\n';
115
+ }
116
+ result.frames.push({
117
+ location,
118
+ code: formattedCodeFrame
119
+ });
120
+ }
121
+ }
122
+ if (stack != null) {
123
+ result.stack = stack;
124
+ }
125
+ if (Array.isArray(hints) && hints.length) {
126
+ result.hints = hints.map(h => {
127
+ return md(h);
128
+ });
129
+ }
130
+ if (documentationURL != null) {
131
+ result.documentation = terminalLink('Learn more', documentationURL, {
132
+ fallback: (text, url) => `${text}: ${url}`
133
+ });
134
+ }
135
+ return result;
136
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getProgressMessage = getProgressMessage;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function getProgressMessage(event) {
16
+ switch (event.phase) {
17
+ case 'transforming':
18
+ return `Building ${_path().default.basename(event.filePath)}...`;
19
+ case 'bundling':
20
+ return 'Bundling...';
21
+ case 'packaging':
22
+ return `Packaging ${event.bundle.displayName}...`;
23
+ case 'optimizing':
24
+ return `Optimizing ${event.bundle.displayName}...`;
25
+ }
26
+ return null;
27
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.relativeBundlePath = relativeBundlePath;
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
+ function relativeBundlePath(from, to, opts = {
17
+ leadingDotSlash: true
18
+ }) {
19
+ let fromPath = _path().default.join(from.target.distDir, from.name);
20
+ let toPath = _path().default.join(to.target.distDir, to.name);
21
+ return (0, _path2.relativePath)(_path().default.dirname(fromPath), toPath, opts.leadingDotSlash);
22
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = relativeUrl;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _url() {
15
+ const data = _interopRequireDefault(require("url"));
16
+ _url = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ function relativeUrl(from, to) {
23
+ return _url().default.format(_url().default.parse(_path().default.relative(from, to)));
24
+ }
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getURLReplacement = getURLReplacement;
7
+ exports.replaceInlineReferences = replaceInlineReferences;
8
+ exports.replaceURLReferences = replaceURLReferences;
9
+ function _rust() {
10
+ const data = require("@atlaspack/rust");
11
+ _rust = function () {
12
+ return data;
13
+ };
14
+ return data;
15
+ }
16
+ function _featureFlags() {
17
+ const data = require("@atlaspack/feature-flags");
18
+ _featureFlags = function () {
19
+ return data;
20
+ };
21
+ return data;
22
+ }
23
+ function _stream() {
24
+ const data = require("stream");
25
+ _stream = function () {
26
+ return data;
27
+ };
28
+ return data;
29
+ }
30
+ function _nullthrows() {
31
+ const data = _interopRequireDefault(require("nullthrows"));
32
+ _nullthrows = function () {
33
+ return data;
34
+ };
35
+ return data;
36
+ }
37
+ function _assert() {
38
+ const data = _interopRequireDefault(require("assert"));
39
+ _assert = function () {
40
+ return data;
41
+ };
42
+ return data;
43
+ }
44
+ function _url() {
45
+ const data = _interopRequireDefault(require("url"));
46
+ _url = function () {
47
+ return data;
48
+ };
49
+ return data;
50
+ }
51
+ var _ = require("./");
52
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
53
+ /*
54
+ * Replaces references to dependency ids for URL dependencies with:
55
+ * - in the case of an unresolvable url dependency, the original specifier.
56
+ * These are external requests that Parcel did not bundle.
57
+ * - in the case of a reference to another bundle, the relative url to that
58
+ * bundle from the current bundle.
59
+ */
60
+ function replaceURLReferences({
61
+ bundle,
62
+ bundleGraph,
63
+ contents,
64
+ map,
65
+ getReplacement = s => s,
66
+ relative = true
67
+ }) {
68
+ let replacements = new Map();
69
+ let urlDependencies = [];
70
+ bundle.traverse(node => {
71
+ if (node.type === 'dependency' && node.value.specifierType === 'url') {
72
+ urlDependencies.push(node.value);
73
+ }
74
+ });
75
+ for (let dependency of urlDependencies) {
76
+ var _dependency$meta;
77
+ if (dependency.specifierType !== 'url') {
78
+ continue;
79
+ }
80
+ let placeholder = ((_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.placeholder) ?? dependency.id;
81
+ (0, _assert().default)(typeof placeholder === 'string');
82
+ let resolved = bundleGraph.getReferencedBundle(dependency, bundle);
83
+ if (resolved == null) {
84
+ replacements.set(placeholder, {
85
+ from: placeholder,
86
+ to: getReplacement(dependency.specifier)
87
+ });
88
+ continue;
89
+ }
90
+ if (resolved.bundleBehavior === 'inline') {
91
+ // If a bundle is inline, it should be replaced with inline contents,
92
+ // not a URL.
93
+ continue;
94
+ }
95
+ replacements.set(placeholder, getURLReplacement({
96
+ dependency,
97
+ fromBundle: bundle,
98
+ toBundle: resolved,
99
+ relative,
100
+ getReplacement
101
+ }));
102
+ }
103
+ return performReplacement(replacements, contents, map);
104
+ }
105
+
106
+ /*
107
+ * Replaces references to dependency ids for inline bundles with the packaged
108
+ * contents of that bundle.
109
+ */
110
+ async function replaceInlineReferences({
111
+ bundle,
112
+ bundleGraph,
113
+ contents,
114
+ map,
115
+ getInlineReplacement,
116
+ getInlineBundleContents
117
+ }) {
118
+ let replacements = new Map();
119
+ let dependencies = [];
120
+ bundle.traverse(node => {
121
+ if (node.type === 'dependency') {
122
+ dependencies.push(node.value);
123
+ }
124
+ });
125
+ for (let dependency of dependencies) {
126
+ let entryBundle = bundleGraph.getReferencedBundle(dependency, bundle);
127
+ if ((entryBundle === null || entryBundle === void 0 ? void 0 : entryBundle.bundleBehavior) !== 'inline') {
128
+ continue;
129
+ }
130
+ let packagedBundle = await getInlineBundleContents(entryBundle, bundleGraph);
131
+ let packagedContents = (packagedBundle.contents instanceof _stream().Readable ? await (0, _.bufferStream)(packagedBundle.contents) : packagedBundle.contents).toString();
132
+ let inlineType = (0, _nullthrows().default)(entryBundle.getMainEntry()).meta.inlineType;
133
+ if (inlineType == null || inlineType === 'string') {
134
+ var _dependency$meta2;
135
+ let placeholder = ((_dependency$meta2 = dependency.meta) === null || _dependency$meta2 === void 0 ? void 0 : _dependency$meta2.placeholder) ?? dependency.id;
136
+ (0, _assert().default)(typeof placeholder === 'string');
137
+ replacements.set(placeholder, getInlineReplacement(dependency, inlineType, packagedContents));
138
+ }
139
+ }
140
+ return performReplacement(replacements, contents, map);
141
+ }
142
+ function getURLReplacement({
143
+ dependency,
144
+ fromBundle,
145
+ toBundle,
146
+ relative,
147
+ getReplacement
148
+ }) {
149
+ var _dependency$meta3;
150
+ let to;
151
+ let orig = _url().default.parse(dependency.specifier);
152
+ if (relative) {
153
+ to = _url().default.format({
154
+ pathname: (0, _.relativeBundlePath)(fromBundle, toBundle, {
155
+ leadingDotSlash: false
156
+ }),
157
+ hash: orig.hash
158
+ });
159
+
160
+ // If the resulting path includes a colon character and doesn't start with a ./ or ../
161
+ // we need to add one so that the first part before the colon isn't parsed as a URL protocol.
162
+ if (to.includes(':') && !to.startsWith('./') && !to.startsWith('../')) {
163
+ to = './' + to;
164
+ }
165
+ } else {
166
+ to = (0, _.urlJoin)(toBundle.target.publicUrl, _url().default.format({
167
+ pathname: (0, _nullthrows().default)(toBundle.name),
168
+ hash: orig.hash
169
+ }));
170
+ }
171
+ let placeholder = ((_dependency$meta3 = dependency.meta) === null || _dependency$meta3 === void 0 ? void 0 : _dependency$meta3.placeholder) ?? dependency.id;
172
+ (0, _assert().default)(typeof placeholder === 'string');
173
+ return {
174
+ from: placeholder,
175
+ to: getReplacement ? getReplacement(to) : to
176
+ };
177
+ }
178
+ function performReplacement(replacements, contents, map) {
179
+ let finalContents = contents;
180
+ if ((0, _featureFlags().getFeatureFlag)('inlineStringReplacementPerf')) {
181
+ let replacementList = Array.from(replacements.values());
182
+ if (replacementList.length > 0) {
183
+ finalContents = (0, _rust().performStringReplacements)(contents, replacementList);
184
+ }
185
+ } else {
186
+ for (let {
187
+ from,
188
+ to
189
+ } of replacements.values()) {
190
+ // Perform replacement
191
+ finalContents = finalContents.split(from).join(to);
192
+ }
193
+ }
194
+ return {
195
+ contents: finalContents,
196
+ // TODO: Update sourcemap with adjusted contents
197
+ map
198
+ };
199
+ }