@exodus/test 1.0.0-rc.61 → 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.
Files changed (2) hide show
  1. package/bundler/bundle.js +20 -5
  2. 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, readFileSync } from 'node:fs'
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 loadSourceFile = async (filepath) => {
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,7 +173,7 @@ 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
- loadPipeline.push(async (source) => {
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)) {
@@ -174,7 +181,7 @@ export const build = async (...files) => {
174
181
  if (file && /^[a-z0-9@_./-]+$/iu.test(file)) {
175
182
  file = resolve(file)
176
183
  if (!file.startsWith(`${cwd}/`)) continue
177
- const data = readFileSync(file, 'base64')
184
+ const data = await readFile(file, 'base64')
178
185
  if (fsFilesContents.has(file)) {
179
186
  assert(fsFilesContents.get(file) === data)
180
187
  } else {
@@ -187,6 +194,13 @@ export const build = async (...files) => {
187
194
  return source
188
195
  })
189
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
+
190
204
  const hasBuffer = ['node', 'bun'].includes(options.platform)
191
205
  const api = (f) => resolveRequire(`./modules/${f}`)
192
206
  const nodeUnprefixed = {
@@ -309,8 +323,9 @@ export const build = async (...files) => {
309
323
  ],
310
324
  }
311
325
 
312
- if (files.length === 1)
326
+ if (files.length === 1) {
313
327
  config.define['process.argv'] = stringify(['exodus-test', resolve(files[0])])
328
+ }
314
329
 
315
330
  let res = await buildWrap(config)
316
331
  assert.equal(res instanceof Error, res.errors.length > 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/test",
3
- "version": "1.0.0-rc.61",
3
+ "version": "1.0.0-rc.62",
4
4
  "author": "Exodus Movement, Inc.",
5
5
  "description": "A test suite runner",
6
6
  "homepage": "https://github.com/ExodusMovement/test",