@utoo/pack 0.0.1-alpha.56 → 0.0.1-alpha.57

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/cjs/build.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = build;
4
+ const pack_shared_1 = require("@utoo/pack-shared");
4
5
  const child_process_1 = require("child_process");
5
6
  const fs_1 = require("fs");
6
7
  const nanoid_1 = require("nanoid");
@@ -50,22 +51,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
50
51
  persistentCaching: false,
51
52
  });
52
53
  const entrypoints = await project.writeAllEntrypointsToDisk();
53
- const topLevelErrors = [];
54
- const topLevelWarnings = [];
55
- for (const issue of entrypoints.issues) {
56
- if (issue.severity === "error" || issue.severity === "fatal") {
57
- topLevelErrors.push((0, util_1.formatIssue)(issue));
58
- }
59
- else if ((0, util_1.isRelevantWarning)(issue)) {
60
- topLevelWarnings.push((0, util_1.formatIssue)(issue));
61
- }
62
- }
63
- if (topLevelWarnings.length > 0) {
64
- console.warn(`Utoopack build encountered ${topLevelWarnings.length} warnings:\n${topLevelWarnings.join("\n")}`);
65
- }
66
- if (topLevelErrors.length > 0) {
67
- throw new Error(`Utoopack build failed with ${topLevelErrors.length} errors:\n${topLevelErrors.join("\n")}`);
68
- }
54
+ (0, pack_shared_1.handleIssues)(entrypoints.issues);
69
55
  await project.shutdown();
70
56
  if (process.env.ANALYZE) {
71
57
  await analyzeBundle(projectPath || process.cwd(), ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || "dist");
package/cjs/types.d.ts CHANGED
@@ -170,6 +170,7 @@ export interface ConfigComplete {
170
170
  experimental?: ExperimentalConfig;
171
171
  persistentCaching?: boolean;
172
172
  cacheHandler?: string;
173
+ nodePolyfill?: boolean;
173
174
  }
174
175
  export interface StyledComponentsConfig {
175
176
  /**
@@ -276,19 +277,3 @@ export interface Endpoint {
276
277
  */
277
278
  serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult>>;
278
279
  }
279
- export type StyledString = {
280
- type: "text";
281
- value: string;
282
- } | {
283
- type: "code";
284
- value: string;
285
- } | {
286
- type: "strong";
287
- value: string;
288
- } | {
289
- type: "stack";
290
- value: StyledString[];
291
- } | {
292
- type: "line";
293
- value: StyledString[];
294
- };
package/cjs/util.d.ts CHANGED
@@ -1,13 +1,10 @@
1
1
  import { NapiIssue } from "./binding";
2
- import { ConfigComplete, DefineEnv, RustifiedEnv, StyledString } from "./types";
2
+ import { ConfigComplete, DefineEnv, RustifiedEnv } from "./types";
3
3
  export declare class ModuleBuildError extends Error {
4
4
  name: string;
5
5
  }
6
6
  export declare function processIssues(result: TurbopackResult, throwIssue: boolean, logErrors: boolean): void;
7
7
  export declare function isWellKnownError(issue: NapiIssue): boolean;
8
- export declare function formatIssue(issue: NapiIssue): string;
9
- export declare function renderStyledStringToErrorAnsi(string: StyledString): string;
10
- export declare function isRelevantWarning(issue: NapiIssue): boolean;
11
8
  export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
12
9
  interface DefineEnvOptions {
13
10
  config: ConfigComplete;
package/cjs/util.js CHANGED
@@ -6,18 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ModuleBuildError = void 0;
7
7
  exports.processIssues = processIssues;
8
8
  exports.isWellKnownError = isWellKnownError;
9
- exports.formatIssue = formatIssue;
10
- exports.renderStyledStringToErrorAnsi = renderStyledStringToErrorAnsi;
11
- exports.isRelevantWarning = isRelevantWarning;
12
9
  exports.rustifyEnv = rustifyEnv;
13
10
  exports.createDefineEnv = createDefineEnv;
14
11
  exports.debounce = debounce;
15
12
  exports.blockStdout = blockStdout;
16
13
  exports.getPackPath = getPackPath;
17
- const code_frame_1 = require("@babel/code-frame");
14
+ const pack_shared_1 = require("@utoo/pack-shared");
18
15
  const path_1 = __importDefault(require("path"));
19
- const picocolors_1 = require("picocolors");
20
- const magicIdentifier_1 = require("./magicIdentifier");
21
16
  class ModuleBuildError extends Error {
22
17
  constructor() {
23
18
  super(...arguments);
@@ -34,12 +29,12 @@ function processIssues(result, throwIssue, logErrors) {
34
29
  continue;
35
30
  if (issue.severity !== "warning") {
36
31
  if (throwIssue) {
37
- const formatted = formatIssue(issue);
32
+ const formatted = (0, pack_shared_1.formatIssue)(issue);
38
33
  relevantIssues.add(formatted);
39
34
  }
40
35
  // if we throw the issue it will most likely get handed and logged elsewhere
41
36
  else if (logErrors && isWellKnownError(issue)) {
42
- const formatted = formatIssue(issue);
37
+ const formatted = (0, pack_shared_1.formatIssue)(issue);
43
38
  console.error(formatted);
44
39
  }
45
40
  }
@@ -50,7 +45,7 @@ function processIssues(result, throwIssue, logErrors) {
50
45
  }
51
46
  function isWellKnownError(issue) {
52
47
  const { title } = issue;
53
- const formattedTitle = renderStyledStringToErrorAnsi(title);
48
+ const formattedTitle = (0, pack_shared_1.renderStyledStringToErrorAnsi)(title);
54
49
  // TODO: add more well known errors
55
50
  if (formattedTitle.includes("Module not found") ||
56
51
  formattedTitle.includes("Unknown module type")) {
@@ -58,94 +53,6 @@ function isWellKnownError(issue) {
58
53
  }
59
54
  return false;
60
55
  }
61
- function formatIssue(issue) {
62
- const { filePath, title, description, source } = issue;
63
- let { documentationLink } = issue;
64
- let formattedTitle = renderStyledStringToErrorAnsi(title).replace(/\n/g, "\n ");
65
- let formattedFilePath = filePath
66
- .replace("[project]/", "./")
67
- .replaceAll("/./", "/")
68
- .replace("\\\\?\\", "");
69
- let message = "";
70
- if (source && source.range) {
71
- const { start } = source.range;
72
- message = `${formattedFilePath}:${start.line + 1}:${start.column + 1}\n${formattedTitle}`;
73
- }
74
- else if (formattedFilePath) {
75
- message = `${formattedFilePath}\n${formattedTitle}`;
76
- }
77
- else {
78
- message = formattedTitle;
79
- }
80
- message += "\n";
81
- if ((source === null || source === void 0 ? void 0 : source.range) && source.source.content) {
82
- const { start, end } = source.range;
83
- message +=
84
- (0, code_frame_1.codeFrameColumns)(source.source.content, {
85
- start: {
86
- line: start.line + 1,
87
- column: start.column + 1,
88
- },
89
- end: {
90
- line: end.line + 1,
91
- column: end.column + 1,
92
- },
93
- }, { forceColor: true }).trim() + "\n\n";
94
- }
95
- if (description) {
96
- message += renderStyledStringToErrorAnsi(description) + "\n\n";
97
- }
98
- // TODO: make it possible to enable this for debugging, but not in tests.
99
- // if (detail) {
100
- // message += renderStyledStringToErrorAnsi(detail) + '\n\n'
101
- // }
102
- // TODO: Include a trace from the issue.
103
- if (documentationLink) {
104
- message += documentationLink + "\n\n";
105
- }
106
- return message;
107
- }
108
- function renderStyledStringToErrorAnsi(string) {
109
- function decodeMagicIdentifiers(str) {
110
- return str.replaceAll(magicIdentifier_1.MAGIC_IDENTIFIER_REGEX, (ident) => {
111
- try {
112
- return (0, picocolors_1.magenta)(`{${(0, magicIdentifier_1.decodeMagicIdentifier)(ident)}}`);
113
- }
114
- catch (e) {
115
- return (0, picocolors_1.magenta)(`{${ident} (decoding failed: ${e})}`);
116
- }
117
- });
118
- }
119
- switch (string.type) {
120
- case "text":
121
- return decodeMagicIdentifiers(string.value);
122
- case "strong":
123
- return (0, picocolors_1.bold)((0, picocolors_1.red)(decodeMagicIdentifiers(string.value)));
124
- case "code":
125
- return (0, picocolors_1.green)(decodeMagicIdentifiers(string.value));
126
- case "line":
127
- return string.value.map(renderStyledStringToErrorAnsi).join("");
128
- case "stack":
129
- return string.value.map(renderStyledStringToErrorAnsi).join("\n");
130
- default:
131
- throw new Error("Unknown StyledString type", string);
132
- }
133
- }
134
- function isRelevantWarning(issue) {
135
- return issue.severity === "warning" && !isNodeModulesIssue(issue);
136
- }
137
- function isNodeModulesIssue(issue) {
138
- if (issue.severity === "warning" && issue.stage === "config") {
139
- // Override for the externalize issue
140
- // `Package foo (serverExternalPackages or default list) can't be external`
141
- if (renderStyledStringToErrorAnsi(issue.title).includes("can't be external")) {
142
- return false;
143
- }
144
- }
145
- return (issue.severity === "warning" &&
146
- (issue.filePath.match(/^(?:.*[\\/])?node_modules(?:[\\/].*)?$/) !== null ||
147
- issue.filePath.includes("@utoo/pack")));
148
- }
149
56
  function rustifyEnv(env) {
150
57
  return Object.entries(env)
151
58
  .filter(([_, value]) => value != null)
package/esm/build.js CHANGED
@@ -1,10 +1,11 @@
1
+ import { handleIssues } from "@utoo/pack-shared";
1
2
  import { spawn } from "child_process";
2
3
  import { existsSync } from "fs";
3
4
  import { nanoid } from "nanoid";
4
5
  import { join } from "path";
5
6
  import { findRootDir } from "./find-root";
6
7
  import { projectFactory } from "./project";
7
- import { blockStdout, createDefineEnv, formatIssue, getPackPath, isRelevantWarning, } from "./util";
8
+ import { blockStdout, createDefineEnv, getPackPath } from "./util";
8
9
  import { compatOptionsFromWebpack } from "./webpackCompat";
9
10
  import { xcodeProfilingReady } from "./xcodeProfile";
10
11
  export function build(options, projectPath, rootPath) {
@@ -47,22 +48,7 @@ async function buildInternal(bundleOptions, projectPath, rootPath) {
47
48
  persistentCaching: false,
48
49
  });
49
50
  const entrypoints = await project.writeAllEntrypointsToDisk();
50
- const topLevelErrors = [];
51
- const topLevelWarnings = [];
52
- for (const issue of entrypoints.issues) {
53
- if (issue.severity === "error" || issue.severity === "fatal") {
54
- topLevelErrors.push(formatIssue(issue));
55
- }
56
- else if (isRelevantWarning(issue)) {
57
- topLevelWarnings.push(formatIssue(issue));
58
- }
59
- }
60
- if (topLevelWarnings.length > 0) {
61
- console.warn(`Utoopack build encountered ${topLevelWarnings.length} warnings:\n${topLevelWarnings.join("\n")}`);
62
- }
63
- if (topLevelErrors.length > 0) {
64
- throw new Error(`Utoopack build failed with ${topLevelErrors.length} errors:\n${topLevelErrors.join("\n")}`);
65
- }
51
+ handleIssues(entrypoints.issues);
66
52
  await project.shutdown();
67
53
  if (process.env.ANALYZE) {
68
54
  await analyzeBundle(projectPath || process.cwd(), ((_d = bundleOptions.config.output) === null || _d === void 0 ? void 0 : _d.path) || "dist");
package/esm/types.d.ts CHANGED
@@ -170,6 +170,7 @@ export interface ConfigComplete {
170
170
  experimental?: ExperimentalConfig;
171
171
  persistentCaching?: boolean;
172
172
  cacheHandler?: string;
173
+ nodePolyfill?: boolean;
173
174
  }
174
175
  export interface StyledComponentsConfig {
175
176
  /**
@@ -276,19 +277,3 @@ export interface Endpoint {
276
277
  */
277
278
  serverChanged(includeIssues: boolean): Promise<AsyncIterableIterator<TurbopackResult>>;
278
279
  }
279
- export type StyledString = {
280
- type: "text";
281
- value: string;
282
- } | {
283
- type: "code";
284
- value: string;
285
- } | {
286
- type: "strong";
287
- value: string;
288
- } | {
289
- type: "stack";
290
- value: StyledString[];
291
- } | {
292
- type: "line";
293
- value: StyledString[];
294
- };
package/esm/util.d.ts CHANGED
@@ -1,13 +1,10 @@
1
1
  import { NapiIssue } from "./binding";
2
- import { ConfigComplete, DefineEnv, RustifiedEnv, StyledString } from "./types";
2
+ import { ConfigComplete, DefineEnv, RustifiedEnv } from "./types";
3
3
  export declare class ModuleBuildError extends Error {
4
4
  name: string;
5
5
  }
6
6
  export declare function processIssues(result: TurbopackResult, throwIssue: boolean, logErrors: boolean): void;
7
7
  export declare function isWellKnownError(issue: NapiIssue): boolean;
8
- export declare function formatIssue(issue: NapiIssue): string;
9
- export declare function renderStyledStringToErrorAnsi(string: StyledString): string;
10
- export declare function isRelevantWarning(issue: NapiIssue): boolean;
11
8
  export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
12
9
  interface DefineEnvOptions {
13
10
  config: ConfigComplete;
package/esm/util.js CHANGED
@@ -1,7 +1,5 @@
1
- import { codeFrameColumns } from "@babel/code-frame";
1
+ import { formatIssue, renderStyledStringToErrorAnsi } from "@utoo/pack-shared";
2
2
  import path from "path";
3
- import { bold, green, magenta, red } from "picocolors";
4
- import { decodeMagicIdentifier, MAGIC_IDENTIFIER_REGEX, } from "./magicIdentifier";
5
3
  export class ModuleBuildError extends Error {
6
4
  constructor() {
7
5
  super(...arguments);
@@ -41,94 +39,6 @@ export function isWellKnownError(issue) {
41
39
  }
42
40
  return false;
43
41
  }
44
- export function formatIssue(issue) {
45
- const { filePath, title, description, source } = issue;
46
- let { documentationLink } = issue;
47
- let formattedTitle = renderStyledStringToErrorAnsi(title).replace(/\n/g, "\n ");
48
- let formattedFilePath = filePath
49
- .replace("[project]/", "./")
50
- .replaceAll("/./", "/")
51
- .replace("\\\\?\\", "");
52
- let message = "";
53
- if (source && source.range) {
54
- const { start } = source.range;
55
- message = `${formattedFilePath}:${start.line + 1}:${start.column + 1}\n${formattedTitle}`;
56
- }
57
- else if (formattedFilePath) {
58
- message = `${formattedFilePath}\n${formattedTitle}`;
59
- }
60
- else {
61
- message = formattedTitle;
62
- }
63
- message += "\n";
64
- if ((source === null || source === void 0 ? void 0 : source.range) && source.source.content) {
65
- const { start, end } = source.range;
66
- message +=
67
- codeFrameColumns(source.source.content, {
68
- start: {
69
- line: start.line + 1,
70
- column: start.column + 1,
71
- },
72
- end: {
73
- line: end.line + 1,
74
- column: end.column + 1,
75
- },
76
- }, { forceColor: true }).trim() + "\n\n";
77
- }
78
- if (description) {
79
- message += renderStyledStringToErrorAnsi(description) + "\n\n";
80
- }
81
- // TODO: make it possible to enable this for debugging, but not in tests.
82
- // if (detail) {
83
- // message += renderStyledStringToErrorAnsi(detail) + '\n\n'
84
- // }
85
- // TODO: Include a trace from the issue.
86
- if (documentationLink) {
87
- message += documentationLink + "\n\n";
88
- }
89
- return message;
90
- }
91
- export function renderStyledStringToErrorAnsi(string) {
92
- function decodeMagicIdentifiers(str) {
93
- return str.replaceAll(MAGIC_IDENTIFIER_REGEX, (ident) => {
94
- try {
95
- return magenta(`{${decodeMagicIdentifier(ident)}}`);
96
- }
97
- catch (e) {
98
- return magenta(`{${ident} (decoding failed: ${e})}`);
99
- }
100
- });
101
- }
102
- switch (string.type) {
103
- case "text":
104
- return decodeMagicIdentifiers(string.value);
105
- case "strong":
106
- return bold(red(decodeMagicIdentifiers(string.value)));
107
- case "code":
108
- return green(decodeMagicIdentifiers(string.value));
109
- case "line":
110
- return string.value.map(renderStyledStringToErrorAnsi).join("");
111
- case "stack":
112
- return string.value.map(renderStyledStringToErrorAnsi).join("\n");
113
- default:
114
- throw new Error("Unknown StyledString type", string);
115
- }
116
- }
117
- export function isRelevantWarning(issue) {
118
- return issue.severity === "warning" && !isNodeModulesIssue(issue);
119
- }
120
- function isNodeModulesIssue(issue) {
121
- if (issue.severity === "warning" && issue.stage === "config") {
122
- // Override for the externalize issue
123
- // `Package foo (serverExternalPackages or default list) can't be external`
124
- if (renderStyledStringToErrorAnsi(issue.title).includes("can't be external")) {
125
- return false;
126
- }
127
- }
128
- return (issue.severity === "warning" &&
129
- (issue.filePath.match(/^(?:.*[\\/])?node_modules(?:[\\/].*)?$/) !== null ||
130
- issue.filePath.includes("@utoo/pack")));
131
- }
132
42
  export function rustifyEnv(env) {
133
43
  return Object.entries(env)
134
44
  .filter(([_, value]) => value != null)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "0.0.1-alpha.56",
3
+ "version": "0.0.1-alpha.57",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "exports": {
@@ -38,6 +38,7 @@
38
38
  "license": "MIT",
39
39
  "dependencies": {
40
40
  "@utoo/style-loader": "^1.0.0",
41
+ "@utoo/pack-shared": "^0.0.7",
41
42
  "react-refresh": "^0.12.0",
42
43
  "@babel/code-frame": "7.22.5",
43
44
  "@swc/helpers": "0.5.15",
@@ -73,24 +74,25 @@
73
74
  "node": ">= 20"
74
75
  },
75
76
  "scripts": {
77
+ "pretsc": "npm run build --workspace @utoo/pack-shared",
76
78
  "build:cjs": "rm -rf cjs && tsc -p ./tsconfig.json --module commonjs --outDir cjs && cp src/*.d.ts cjs/",
77
79
  "build:esm": "rm -rf esm && tsc -p ./tsconfig.json --module esnext --outDir esm && cp src/*.d.ts esm/",
78
- "build:local": "npm run build:binding:local && npm run build:cjs && npm run build:esm && cp src/*.node cjs/ && cp src/*.node esm/",
80
+ "build:local": "npm run build:binding:local && npm run pretsc && npm run build:cjs && npm run build:esm && cp src/*.node cjs/ && cp src/*.node esm/",
79
81
  "artifacts": "napi artifacts --dir ./src --dist npm",
80
82
  "build:binding": "napi build src --platform --release -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts",
81
83
  "build:binding:local": "napi build src --platform --profile release-local -p pack-napi --cargo-cwd ../../ --cargo-name pack_napi --features plugin --js binding.js --dts binding.d.ts",
82
- "prepublishOnly": "npm run build:esm && npm run build:cjs && napi prepublish -t npm --skip-gh-release",
84
+ "prepublishOnly": "npm run pretsc && npm run build:esm && npm run build:cjs && napi prepublish -t npm --skip-gh-release",
83
85
  "version": "napi version",
84
86
  "generate-features-list": "node ./scripts/generate-feature-list.js"
85
87
  },
86
88
  "repository": "git@github.com:utooland/utoo.git",
87
89
  "optionalDependencies": {
88
- "@utoo/pack-darwin-arm64": "0.0.1-alpha.56",
89
- "@utoo/pack-darwin-x64": "0.0.1-alpha.56",
90
- "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.56",
91
- "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.56",
92
- "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.56",
93
- "@utoo/pack-linux-x64-musl": "0.0.1-alpha.56",
94
- "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.56"
90
+ "@utoo/pack-darwin-arm64": "0.0.1-alpha.57",
91
+ "@utoo/pack-darwin-x64": "0.0.1-alpha.57",
92
+ "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.57",
93
+ "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.57",
94
+ "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.57",
95
+ "@utoo/pack-linux-x64-musl": "0.0.1-alpha.57",
96
+ "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.57"
95
97
  }
96
98
  }
@@ -1,2 +0,0 @@
1
- export declare function decodeMagicIdentifier(identifier: string): string;
2
- export declare const MAGIC_IDENTIFIER_REGEX: RegExp;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MAGIC_IDENTIFIER_REGEX = void 0;
4
- exports.decodeMagicIdentifier = decodeMagicIdentifier;
5
- function decodeHex(hexStr) {
6
- if (hexStr.trim() === "") {
7
- throw new Error("can't decode empty hex");
8
- }
9
- const num = parseInt(hexStr, 16);
10
- if (isNaN(num)) {
11
- throw new Error(`invalid hex: \`${hexStr}\``);
12
- }
13
- return String.fromCodePoint(num);
14
- }
15
- const DECODE_REGEX = /^__TURBOPACK__([a-zA-Z0-9_$]+)__$/;
16
- function decodeMagicIdentifier(identifier) {
17
- const matches = identifier.match(DECODE_REGEX);
18
- if (!matches) {
19
- return identifier;
20
- }
21
- const inner = matches[1];
22
- let output = "";
23
- let mode = 0 /* Mode.Text */;
24
- let buffer = "";
25
- for (let i = 0; i < inner.length; i++) {
26
- const char = inner[i];
27
- if (mode === 0 /* Mode.Text */) {
28
- if (char === "_") {
29
- mode = 1 /* Mode.Underscore */;
30
- }
31
- else if (char === "$") {
32
- mode = 2 /* Mode.Hex */;
33
- }
34
- else {
35
- output += char;
36
- }
37
- }
38
- else if (mode === 1 /* Mode.Underscore */) {
39
- if (char === "_") {
40
- output += " ";
41
- mode = 0 /* Mode.Text */;
42
- }
43
- else if (char === "$") {
44
- output += "_";
45
- mode = 2 /* Mode.Hex */;
46
- }
47
- else {
48
- output += char;
49
- mode = 0 /* Mode.Text */;
50
- }
51
- }
52
- else if (mode === 2 /* Mode.Hex */) {
53
- if (buffer.length === 2) {
54
- output += decodeHex(buffer);
55
- buffer = "";
56
- }
57
- if (char === "_") {
58
- if (buffer !== "") {
59
- throw new Error(`invalid hex: \`${buffer}\``);
60
- }
61
- mode = 3 /* Mode.LongHex */;
62
- }
63
- else if (char === "$") {
64
- if (buffer !== "") {
65
- throw new Error(`invalid hex: \`${buffer}\``);
66
- }
67
- mode = 0 /* Mode.Text */;
68
- }
69
- else {
70
- buffer += char;
71
- }
72
- }
73
- else if (mode === 3 /* Mode.LongHex */) {
74
- if (char === "_") {
75
- throw new Error(`invalid hex: \`${buffer + char}\``);
76
- }
77
- else if (char === "$") {
78
- output += decodeHex(buffer);
79
- buffer = "";
80
- mode = 0 /* Mode.Text */;
81
- }
82
- else {
83
- buffer += char;
84
- }
85
- }
86
- }
87
- return output;
88
- }
89
- exports.MAGIC_IDENTIFIER_REGEX = /__TURBOPACK__[a-zA-Z0-9_$]+__/g;
@@ -1,2 +0,0 @@
1
- export declare function decodeMagicIdentifier(identifier: string): string;
2
- export declare const MAGIC_IDENTIFIER_REGEX: RegExp;
@@ -1,85 +0,0 @@
1
- function decodeHex(hexStr) {
2
- if (hexStr.trim() === "") {
3
- throw new Error("can't decode empty hex");
4
- }
5
- const num = parseInt(hexStr, 16);
6
- if (isNaN(num)) {
7
- throw new Error(`invalid hex: \`${hexStr}\``);
8
- }
9
- return String.fromCodePoint(num);
10
- }
11
- const DECODE_REGEX = /^__TURBOPACK__([a-zA-Z0-9_$]+)__$/;
12
- export function decodeMagicIdentifier(identifier) {
13
- const matches = identifier.match(DECODE_REGEX);
14
- if (!matches) {
15
- return identifier;
16
- }
17
- const inner = matches[1];
18
- let output = "";
19
- let mode = 0 /* Mode.Text */;
20
- let buffer = "";
21
- for (let i = 0; i < inner.length; i++) {
22
- const char = inner[i];
23
- if (mode === 0 /* Mode.Text */) {
24
- if (char === "_") {
25
- mode = 1 /* Mode.Underscore */;
26
- }
27
- else if (char === "$") {
28
- mode = 2 /* Mode.Hex */;
29
- }
30
- else {
31
- output += char;
32
- }
33
- }
34
- else if (mode === 1 /* Mode.Underscore */) {
35
- if (char === "_") {
36
- output += " ";
37
- mode = 0 /* Mode.Text */;
38
- }
39
- else if (char === "$") {
40
- output += "_";
41
- mode = 2 /* Mode.Hex */;
42
- }
43
- else {
44
- output += char;
45
- mode = 0 /* Mode.Text */;
46
- }
47
- }
48
- else if (mode === 2 /* Mode.Hex */) {
49
- if (buffer.length === 2) {
50
- output += decodeHex(buffer);
51
- buffer = "";
52
- }
53
- if (char === "_") {
54
- if (buffer !== "") {
55
- throw new Error(`invalid hex: \`${buffer}\``);
56
- }
57
- mode = 3 /* Mode.LongHex */;
58
- }
59
- else if (char === "$") {
60
- if (buffer !== "") {
61
- throw new Error(`invalid hex: \`${buffer}\``);
62
- }
63
- mode = 0 /* Mode.Text */;
64
- }
65
- else {
66
- buffer += char;
67
- }
68
- }
69
- else if (mode === 3 /* Mode.LongHex */) {
70
- if (char === "_") {
71
- throw new Error(`invalid hex: \`${buffer + char}\``);
72
- }
73
- else if (char === "$") {
74
- output += decodeHex(buffer);
75
- buffer = "";
76
- mode = 0 /* Mode.Text */;
77
- }
78
- else {
79
- buffer += char;
80
- }
81
- }
82
- }
83
- return output;
84
- }
85
- export const MAGIC_IDENTIFIER_REGEX = /__TURBOPACK__[a-zA-Z0-9_$]+__/g;