Skip to content

Commit a2fb88f

Browse files
committed
Rename esm package related constants.
1 parent b6a20cf commit a2fb88f

17 files changed

+73
-80
lines changed

src/caching-compiler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function init() {
3737
} = ENV
3838

3939
const {
40-
PKG_VERSION
40+
PACKAGE_VERSION
4141
} = ESM
4242

4343
const CachingCompiler = {
@@ -393,7 +393,7 @@ function init() {
393393
writeFile(cachePath + sep + ".data.blob", GenericBuffer.concat(buffers))
394394
writeFile(cachePath + sep + ".data.json", JSON.stringify({
395395
map,
396-
version: PKG_VERSION
396+
version: PACKAGE_VERSION
397397
}))
398398
}
399399

src/constant/esm.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
import encodeId from "../util/encode-id.js"
22
import setDeferred from "../util/set-deferred.js"
3+
import stripPrereleaseTag from "../util/strip-prerelease-tag.js"
34

45
// The `process.env` properties are replaced at build time.
56
// https://webpack.js.org/plugins/environment-plugin/
7+
const { PACKAGE_FILENAMES } = process.env
8+
const { PACKAGE_VERSION } = process.env
9+
610
const ESM = {
711
__proto__: null,
8-
PKG_DIRNAME: null,
9-
PKG_FILENAMES: null,
10-
PKG_PREFIX: encodeId("esm"),
11-
PKG_VERSION: process.env.PKG_VERSION
12+
PACKAGE_DIRNAME: null,
13+
PACKAGE_FILENAMES: null,
14+
PACKAGE_PREFIX: encodeId("esm"),
15+
PACKAGE_RANGE: stripPrereleaseTag(PACKAGE_VERSION),
16+
PACKAGE_VERSION
1217
}
1318

1419
const { filename } = __non_webpack_module__
1520

16-
setDeferred(ESM, "PKG_DIRNAME", () => {
21+
setDeferred(ESM, "PACKAGE_DIRNAME", () => {
1722
const { safePath } = __shared__.module
1823

1924
return safePath.dirname(filename)
2025
})
2126

22-
setDeferred(ESM, "PKG_FILENAMES", function () {
27+
setDeferred(ESM, "PACKAGE_FILENAMES", function () {
2328
const { safePath } = __shared__.module
2429
const { sep } = safePath
25-
const { PKG_DIRNAME } = this
26-
const { PKG_FILENAMES } = process.env
30+
const { PACKAGE_DIRNAME } = this
2731

28-
let { length } = PKG_FILENAMES
32+
let { length } = PACKAGE_FILENAMES
2933

3034
while (length--) {
31-
PKG_FILENAMES[length] = PKG_DIRNAME + sep + PKG_FILENAMES[length]
35+
PACKAGE_FILENAMES[length] = PACKAGE_DIRNAME + sep + PACKAGE_FILENAMES[length]
3236
}
3337

34-
return PKG_FILENAMES
38+
return PACKAGE_FILENAMES
3539
})
3640

3741
export default ESM

src/error/scrub-stack-trace.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import shared from "../shared.js"
44

55
function init() {
66
const {
7-
PKG_FILENAMES
7+
PACKAGE_FILENAMES
88
} = ESM
99

1010
const columnInfoRegExp = /:1:\d+(?=\)?$)/gm
@@ -29,7 +29,7 @@ function init() {
2929

3030
return message + lines
3131
.filter((line) => {
32-
for (const filename of PKG_FILENAMES) {
32+
for (const filename of PACKAGE_FILENAMES) {
3333
if (line.indexOf(filename) !== -1) {
3434
return false
3535
}

src/errors.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import toStringLiteral from "./util/to-string-literal.js"
1313

1414
function init() {
1515
const {
16-
PKG_VERSION
16+
PACKAGE_VERSION
1717
} = ESM
1818

1919
const {
@@ -184,7 +184,7 @@ function init() {
184184
}
185185

186186
function invalidPkgOption(name, value, unquoted) {
187-
return "The esm@" + PKG_VERSION + " option " +
187+
return "The esm@" + PACKAGE_VERSION + " option " +
188188
(unquoted ? toString(name) : toStringLiteral(name, "'")) +
189189
" is invalid. Received " + truncInspect(value)
190190
}
@@ -237,7 +237,7 @@ function init() {
237237
}
238238

239239
function unknownPkgOption(name) {
240-
return "Unknown esm@" + PKG_VERSION + " option: " + name
240+
return "Unknown esm@" + PACKAGE_VERSION + " option: " + name
241241
}
242242

243243
function undefinedIdentifier(name) {

src/hook/module.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const {
4444
} = ENV
4545

4646
const {
47-
PKG_VERSION
47+
PACKAGE_VERSION
4848
} = ESM
4949

5050
const {
@@ -255,10 +255,10 @@ function tryPassthru(func, args, pkg) {
255255
const { range } = pkg
256256

257257
if (importExportRegExp.test(message) &&
258-
! satisfies(PKG_VERSION, range)) {
258+
! satisfies(PACKAGE_VERSION, range)) {
259259
const newMessage =
260260
"Expected esm@" + range +
261-
". Using esm@" + PKG_VERSION + ": " + filename
261+
". Using esm@" + PACKAGE_VERSION + ": " + filename
262262

263263
set(error, "message", newMessage)
264264

src/hook/process.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@ import isError from "../util/is-error.js"
77
import isStackTraceMasked from "../util/is-stack-trace-masked.js"
88
import maskStackTrace from "../error/mask-stack-trace.js"
99
import scrubStackTrace from "../error/scrub-stack-trace.js"
10-
import stripPrereleaseTag from "../util/strip-prerelease-tag.js"
1110

1211
const {
13-
PKG_VERSION
12+
PACKAGE_RANGE
1413
} = ESM
1514

16-
const wrapperRange = stripPrereleaseTag(PKG_VERSION)
17-
1815
function hook(process) {
1916
function exceptionManagerWrapper(manager, func, args) {
20-
const wrapped = Wrapper.find(process, "_fatalException", wrapperRange)
17+
const wrapped = Wrapper.find(process, "_fatalException", PACKAGE_RANGE)
2118

2219
return wrapped
2320
? Reflect.apply(wrapped, this, [manager, func, args])
@@ -37,7 +34,7 @@ function hook(process) {
3734
}
3835

3936
function warningManagerWrapper(manager, func, args) {
40-
const wrapped = Wrapper.find(process, "emitWarning", wrapperRange)
37+
const wrapped = Wrapper.find(process, "emitWarning", PACKAGE_RANGE)
4138

4239
return wrapped
4340
? Reflect.apply(wrapped, this, [manager, func, args])

src/module/internal/make-require-function.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const {
2323
} = ENTRY
2424

2525
const {
26-
PKG_DIRNAME
26+
PACKAGE_DIRNAME
2727
} = ESM
2828

2929
const {
@@ -116,7 +116,7 @@ function isOwnModule(mod) {
116116
const { filename } = mod
117117

118118
return typeof filename === "string" &&
119-
filename.startsWith(PKG_DIRNAME)
119+
filename.startsWith(PACKAGE_DIRNAME)
120120
}
121121

122122
function ownRequire(request) {

src/module/internal/resolve-lookup-paths.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const {
1818
} = ENV
1919

2020
const {
21-
PKG_DIRNAME
21+
PACKAGE_DIRNAME
2222
} = ESM
2323

2424
let availableModulesPath
@@ -41,7 +41,7 @@ function resolveLookupPaths(request, parent, skipGlobalPaths) {
4141

4242
if (RUNKIT) {
4343
if (availableModulesPath === void 0) {
44-
availableModulesPath = dirname(PKG_DIRNAME)
44+
availableModulesPath = dirname(PACKAGE_DIRNAME)
4545
}
4646

4747
paths.push(availableModulesPath)

src/own/proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import shared from "../shared.js"
44

55
function init() {
66
const {
7-
PKG_PREFIX
7+
PACKAGE_PREFIX
88
} = ESM
99

1010
const customInspectDescriptor = {
@@ -30,7 +30,7 @@ function init() {
3030
handler = { __proto__: handler }
3131

3232
Reflect.defineProperty(handler, shared.customInspectKey, customInspectDescriptor)
33-
Reflect.defineProperty(handler, PKG_PREFIX + ":proxy", markerDescriptor)
33+
Reflect.defineProperty(handler, PACKAGE_PREFIX + ":proxy", markerDescriptor)
3434
Object.freeze(handler)
3535

3636
const proxy = new Proxy(target, handler)

src/package.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import readJSON6 from "./fs/read-json6.js"
2929
import readdir from "./fs/readdir.js"
3030
import removeFile from "./fs/remove-file.js"
3131
import shared from "./shared.js"
32-
import stripPrereleaseTag from "./util/strip-prerelease-tag.js"
3332
import toStringLiteral from "./util/to-string-literal.js"
3433
import { validRange } from "semver"
3534

@@ -42,7 +41,8 @@ const {
4241
} = ENV
4342

4443
const {
45-
PKG_VERSION
44+
PACKAGE_RANGE,
45+
PACKAGE_VERSION
4646
} = ESM
4747

4848
const {
@@ -58,7 +58,7 @@ const {
5858
} = errors
5959

6060
const ESMRC_FILENAME = ".esmrc"
61-
const PACKAGE_FILENAME = "package.json"
61+
const PACKAGE_JSON_FILENAME = "package.json"
6262

6363
const defaultOptions = {
6464
await: false,
@@ -159,7 +159,7 @@ class Package {
159159
isCacheInvalid =
160160
json === null ||
161161
! has(json, "version") ||
162-
json.version !== PKG_VERSION ||
162+
json.version !== PACKAGE_VERSION ||
163163
! has(json, "map") ||
164164
! isObject(json.map)
165165
}
@@ -418,7 +418,7 @@ function createOptions(value) {
418418

419419
function findRoot(dirPath) {
420420
if (basename(dirPath) === "node_modules" ||
421-
isFile(dirPath + sep + PACKAGE_FILENAME)) {
421+
isFile(dirPath + sep + PACKAGE_JSON_FILENAME)) {
422422
return dirPath
423423
}
424424

@@ -548,7 +548,7 @@ function readInfo(dirPath, forceOptions = false) {
548548
}
549549
}
550550

551-
const pkgPath = dirPath + sep + PACKAGE_FILENAME
551+
const pkgPath = dirPath + sep + PACKAGE_JSON_FILENAME
552552

553553
let pkgJSON = isFile(pkgPath)
554554
? readFile(pkgPath, "utf8")
@@ -645,7 +645,7 @@ if (! Reflect.has(state, cacheKey)) {
645645
}
646646

647647
if (! Reflect.has(state[cacheKey].cache, "")) {
648-
state[cacheKey].cache[""] = new Package("", stripPrereleaseTag(PKG_VERSION), {
648+
state[cacheKey].cache[""] = new Package("", PACKAGE_RANGE, {
649649
cache: false,
650650
cjs: true
651651
})

src/shared.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import encodeId from "./util/encode-id.js"
44
import setDeferred from "./util/set-deferred.js"
55

66
const {
7-
PKG_PREFIX,
8-
PKG_VERSION
7+
PACKAGE_PREFIX,
8+
PACKAGE_VERSION
99
} = ESM
1010

11-
const SHARED_SYMBOL = Symbol.for(PKG_PREFIX + "@" + PKG_VERSION + ":shared")
11+
const SHARED_SYMBOL = Symbol.for(PACKAGE_PREFIX + "@" + PACKAGE_VERSION + ":shared")
1212

1313
function getShared() {
1414
if (__shared__ !== void 0) {
@@ -31,7 +31,7 @@ function getShared() {
3131

3232
function init() {
3333
const dummyProxy = new Proxy(class {}, {
34-
[PKG_PREFIX]: 1
34+
[PACKAGE_PREFIX]: 1
3535
})
3636

3737
const funcToString = Function.prototype.toString
@@ -41,16 +41,16 @@ function init() {
4141
}
4242

4343
const symbol = {
44-
_compile: Symbol.for(PKG_PREFIX + ":module._compile"),
45-
entry: Symbol.for(PKG_PREFIX + ":entry"),
46-
mjs: Symbol.for(PKG_PREFIX + ':Module._extensions[".mjs"]'),
47-
namespace: Symbol.for(PKG_PREFIX + ":namespace"),
48-
package: Symbol.for(PKG_PREFIX + ":package"),
49-
realGetProxyDetails: Symbol.for(PKG_PREFIX + ":realGetProxyDetails"),
50-
realRequire: Symbol.for(PKG_PREFIX + ":realRequire"),
51-
runtime: Symbol.for(PKG_PREFIX + ":runtime"),
44+
_compile: Symbol.for(PACKAGE_PREFIX + ":module._compile"),
45+
entry: Symbol.for(PACKAGE_PREFIX + ":entry"),
46+
mjs: Symbol.for(PACKAGE_PREFIX + ':Module._extensions[".mjs"]'),
47+
namespace: Symbol.for(PACKAGE_PREFIX + ":namespace"),
48+
package: Symbol.for(PACKAGE_PREFIX + ":package"),
49+
realGetProxyDetails: Symbol.for(PACKAGE_PREFIX + ":realGetProxyDetails"),
50+
realRequire: Symbol.for(PACKAGE_PREFIX + ":realRequire"),
51+
runtime: Symbol.for(PACKAGE_PREFIX + ":runtime"),
5252
shared: SHARED_SYMBOL,
53-
wrapper: Symbol.for(PKG_PREFIX + ":wrapper")
53+
wrapper: Symbol.for(PACKAGE_PREFIX + ":wrapper")
5454
}
5555

5656
const utilBinding = {}
@@ -199,7 +199,7 @@ function init() {
199199
})
200200

201201
return inspected.indexOf("Proxy") !== -1 &&
202-
inspected.indexOf(PKG_PREFIX) !== -1
202+
inspected.indexOf(PACKAGE_PREFIX) !== -1
203203
})
204204

205205
setDeferred(support, "lookupShadowed", () => {

src/util/get-cache-name.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import shared from "../shared.js"
77

88
function init() {
99
const {
10-
PKG_VERSION
10+
PACKAGE_VERSION
1111
} = ESM
1212

1313
const EMPTY_MD5_HASH = "d41d8cd98f00b204e9800998ecf8427e"
@@ -26,7 +26,7 @@ function init() {
2626
}
2727

2828
const stateHash = md5(
29-
PKG_VERSION + "\0" +
29+
PACKAGE_VERSION + "\0" +
3030
JSON.stringify(options.packageOptions) + "\0" +
3131
cacheKey
3232
)

src/util/is-own-path.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import shared from "../shared.js"
44

55
function init() {
66
const {
7-
PKG_FILENAMES
7+
PACKAGE_FILENAMES
88
} = ESM
99

1010
function isOwnPath(thePath) {
1111
if (typeof thePath === "string") {
12-
for (const filename of PKG_FILENAMES) {
12+
for (const filename of PACKAGE_FILENAMES) {
1313
if (thePath === filename) {
1414
return true
1515
}

src/util/is-own-proxy.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import shared from "../shared.js"
88

99
function init() {
1010
const {
11-
PKG_PREFIX
11+
PACKAGE_PREFIX
1212
} = ESM
1313

1414
let inspectDepth = 0
1515

1616
const endMarkerRegExp = new RegExp(
1717
"[\\[\"']" +
18-
PKG_PREFIX +
18+
PACKAGE_PREFIX +
1919
":proxy['\"\\]]\\s*:\\s*1\\s*\\}\\s*.?$"
2020
)
2121

0 commit comments

Comments
 (0)