@exodus/test 1.0.0-rc.60 → 1.0.0-rc.62
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/bundler/bundle.js +25 -7
- package/bundler/modules/fs.cjs +2 -0
- package/bundler/modules/globals.cjs +5 -0
- package/package.json +1 -1
package/bundler/bundle.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
import { readFile } from 'node:fs/promises'
|
|
3
|
-
import { existsSync
|
|
3
|
+
import { existsSync } from 'node:fs'
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
5
5
|
import { basename, dirname, extname, resolve, join } from 'node:path'
|
|
6
6
|
import { createRequire } from 'node:module'
|
|
@@ -95,7 +95,7 @@ const getPackageFiles = async (dir) => {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
const loadCache = new Map()
|
|
98
|
-
const
|
|
98
|
+
const loadSourceFileBase = async (filepath) => {
|
|
99
99
|
if (!loadCache.has(filepath)) {
|
|
100
100
|
const load = async () => {
|
|
101
101
|
let contents = await readFile(filepath, 'utf8')
|
|
@@ -110,6 +110,13 @@ const loadSourceFile = async (filepath) => {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export const build = async (...files) => {
|
|
113
|
+
const specificLoadPipeline = []
|
|
114
|
+
const loadSourceFile = async (filepath) => {
|
|
115
|
+
let contents = await loadSourceFileBase(filepath)
|
|
116
|
+
for (const transform of specificLoadPipeline) contents = await transform(contents, filepath)
|
|
117
|
+
return contents
|
|
118
|
+
}
|
|
119
|
+
|
|
113
120
|
const input = []
|
|
114
121
|
const importSource = async (file) => input.push(await loadSourceFile(resolveRequire(file)))
|
|
115
122
|
const importFile = (...args) => input.push(`await import(${JSON.stringify(resolve(...args))});`)
|
|
@@ -166,14 +173,15 @@ export const build = async (...files) => {
|
|
|
166
173
|
|
|
167
174
|
const fsfiles = await getPackageFiles(filename ? dirname(resolve(filename)) : process.cwd())
|
|
168
175
|
const fsFilesContents = new Map()
|
|
169
|
-
|
|
176
|
+
specificLoadPipeline.push(async (source) => {
|
|
170
177
|
const cwd = process.cwd()
|
|
171
178
|
for (const re of [/readFileSync\('([^'\\]+)'[),]/gu, /readFileSync\("([^"\\]+)"[),]/gu]) {
|
|
172
179
|
for (const match of source.matchAll(re)) {
|
|
173
|
-
|
|
180
|
+
let file = match[1]
|
|
174
181
|
if (file && /^[a-z0-9@_./-]+$/iu.test(file)) {
|
|
175
|
-
|
|
176
|
-
|
|
182
|
+
file = resolve(file)
|
|
183
|
+
if (!file.startsWith(`${cwd}/`)) continue
|
|
184
|
+
const data = await readFile(file, 'base64')
|
|
177
185
|
if (fsFilesContents.has(file)) {
|
|
178
186
|
assert(fsFilesContents.get(file) === data)
|
|
179
187
|
} else {
|
|
@@ -186,6 +194,13 @@ export const build = async (...files) => {
|
|
|
186
194
|
return source
|
|
187
195
|
})
|
|
188
196
|
|
|
197
|
+
if (files.length === 1) {
|
|
198
|
+
const main = resolve(files[0])
|
|
199
|
+
specificLoadPipeline.push((source, filepath) => {
|
|
200
|
+
return source.replaceAll('(require.main === module)', `(${filepath === main})`)
|
|
201
|
+
})
|
|
202
|
+
}
|
|
203
|
+
|
|
189
204
|
const hasBuffer = ['node', 'bun'].includes(options.platform)
|
|
190
205
|
const api = (f) => resolveRequire(`./modules/${f}`)
|
|
191
206
|
const nodeUnprefixed = {
|
|
@@ -246,6 +261,8 @@ export const build = async (...files) => {
|
|
|
246
261
|
'process.type': 'undefined',
|
|
247
262
|
'process.version': stringify('v22.5.1'), // shouldn't depend on currently used Node.js version
|
|
248
263
|
'process.versions.node': stringify('22.5.1'), // see line above
|
|
264
|
+
'process.cwd': 'EXODUS_TEST_PROCESS.cwd',
|
|
265
|
+
EXODUS_TEST_PROCESS_CWD: stringify(process.cwd()),
|
|
249
266
|
EXODUS_TEST_FILES: stringify(files.map((f) => [dirname(f), basename(f)])),
|
|
250
267
|
EXODUS_TEST_SNAPSHOTS: stringify(EXODUS_TEST_SNAPSHOTS),
|
|
251
268
|
EXODUS_TEST_RECORDINGS: stringify(EXODUS_TEST_RECORDINGS),
|
|
@@ -306,8 +323,9 @@ export const build = async (...files) => {
|
|
|
306
323
|
],
|
|
307
324
|
}
|
|
308
325
|
|
|
309
|
-
if (files.length === 1)
|
|
326
|
+
if (files.length === 1) {
|
|
310
327
|
config.define['process.argv'] = stringify(['exodus-test', resolve(files[0])])
|
|
328
|
+
}
|
|
311
329
|
|
|
312
330
|
let res = await buildWrap(config)
|
|
313
331
|
assert.equal(res instanceof Error, res.errors.length > 0)
|
package/bundler/modules/fs.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const constants = require('constants-browserify')
|
|
2
|
+
const { resolve } = require('path')
|
|
2
3
|
const { F_OK, R_OK, W_OK, X_OK } = constants
|
|
3
4
|
|
|
4
5
|
// promises, sync, callbacks
|
|
@@ -97,6 +98,7 @@ const readFileSync = (file, options) => {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
if (typeof file !== 'string') throw new Error('file argument should be string')
|
|
101
|
+
file = resolve(process.cwd(), file)
|
|
100
102
|
if (fsFilesContents?.has(file)) {
|
|
101
103
|
const data = Buffer.from(fsFilesContents.get(file), 'base64')
|
|
102
104
|
if (encoding?.toLowerCase().replace('-', '') === 'utf8') return data.toString('utf8')
|
|
@@ -70,6 +70,11 @@ if (typeof process === 'undefined') {
|
|
|
70
70
|
}, 0)
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
|
+
cwd: () => {
|
|
74
|
+
// eslint-disable-next-line no-undef
|
|
75
|
+
if (typeof EXODUS_TEST_PROCESS_CWD === 'string') return EXODUS_TEST_PROCESS_CWD
|
|
76
|
+
throw new Error('Can not determine cwd, no process available')
|
|
77
|
+
},
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
globalThis.EXODUS_TEST_PROCESS = process
|