| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 62e23f8 commit b5991f5
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,21 +49,21 @@ describe('legacyMainResolve', () => { | |||
| 49 | 49 | ||
| 50 | 50 | const packageJsonUrl = pathToFileURL( | |
| 51 | 51 | path.resolve( | |
| 52 | - '${fixtextureFolderEscaped}', | ||
| 52 | + ${JSON.stringify(fixtextureFolderEscaped)}, | ||
| 53 | 53 | 'package.json' | |
| 54 | 54 | ) | |
| 55 | 55 | ); | |
| 56 | 56 | ||
| 57 | 57 | const packageConfig = { main: '${mainOrFolder}' }; | |
| 58 | 58 | const base = path.resolve( | |
| 59 | - '${fixtextureFolderEscaped}' | ||
| 59 | + ${JSON.stringify(fixtextureFolderEscaped)}, | ||
| 60 | 60 | ); | |
| 61 | 61 | ||
| 62 | 62 | assert.throws(() => legacyMainResolve(packageJsonUrl, packageConfig, base), { | |
| 63 | 63 | code: 'ERR_ACCESS_DENIED', | |
| 64 | 64 | resource: path.resolve( | |
| 65 | - '${fixtextureFolderEscaped}', | ||
| 66 | - '${mainOrFolder}' | ||
| 65 | + ${JSON.stringify(fixtextureFolderEscaped)}, | ||
| 66 | + ${JSON.stringify(mainOrFolder)}, | ||
| 67 | 67 | ) | |
| 68 | 68 | }); | |
| 69 | 69 | `, | |
@@ -103,23 +103,23 @@ describe('legacyMainResolve', () => { | |||
| 103 | 103 | ||
| 104 | 104 | const packageJsonUrl = pathToFileURL( | |
| 105 | 105 | path.resolve( | |
| 106 | - '${fixtextureFolderEscaped}', | ||
| 107 | - '${folder}', | ||
| 106 | + ${JSON.stringify(fixtextureFolderEscaped)}, | ||
| 107 | + ${JSON.stringify(folder)}, | ||
| 108 | 108 | 'package.json' | |
| 109 | 109 | ) | |
| 110 | 110 | ); | |
| 111 | 111 | ||
| 112 | 112 | const packageConfig = { main: undefined }; | |
| 113 | 113 | const base = path.resolve( | |
| 114 | - '${fixtextureFolderEscaped}' | ||
| 114 | + ${JSON.stringify(fixtextureFolderEscaped)}, | ||
| 115 | 115 | ); | |
| 116 | 116 | ||
| 117 | 117 | assert.throws(() => legacyMainResolve(packageJsonUrl, packageConfig, base), { | |
| 118 | 118 | code: 'ERR_ACCESS_DENIED', | |
| 119 | 119 | resource: path.resolve( | |
| 120 | - '${fixtextureFolderEscaped}', | ||
| 121 | - '${folder}', | ||
| 122 | - '${expectedFile}' | ||
| 120 | + ${JSON.stringify(fixtextureFolderEscaped)}, | ||
| 121 | + ${JSON.stringify(folder)}, | ||
| 122 | + ${JSON.stringify(expectedFile)}, | ||
| 123 | 123 | ) | |
| 124 | 124 | }); | |
| 125 | 125 | `, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,11 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | + const { pathToFileURL } = require('url'); | ||
| 3 | 4 | const assert = require('assert'); | |
| 4 | 5 | ||
| 5 | 6 | const relativePath = '../fixtures/es-modules/test-esm-ok.mjs'; | |
| 6 | - const absolutePath = require.resolve('../fixtures/es-modules/test-esm-ok.mjs'); | ||
| 7 | - const targetURL = new URL('file:///'); | ||
| 8 | - targetURL.pathname = absolutePath; | ||
| 7 | + const absolutePath = require.resolve(relativePath); | ||
| 8 | + const targetURL = pathToFileURL(absolutePath); | ||
| 9 | 9 | ||
| 10 | 10 | function expectModuleError(result, code, message) { | |
| 11 | 11 | Promise.resolve(result).catch(common.mustCall((error) => { | |
@@ -41,7 +41,7 @@ function expectFsNamespace(result) { | |||
| 41 | 41 | // expectOkNamespace(import(relativePath)); | |
| 42 | 42 | expectOkNamespace(eval(`import("${relativePath}")`)); | |
| 43 | 43 | expectOkNamespace(eval(`import("${relativePath}")`)); | |
| 44 | - expectOkNamespace(eval(`import("${targetURL}")`)); | ||
| 44 | + expectOkNamespace(eval(`import(${JSON.stringify(targetURL)})`)); | ||
| 45 | 45 | ||
| 46 | 46 | // Importing a built-in, both direct & via eval | |
| 47 | 47 | expectFsNamespace(import('fs')); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => { | |||
| 28 | 28 | fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), | |
| 29 | 29 | '--input-type=module', | |
| 30 | 30 | '--eval', | |
| 31 | - `import '${fixtures.fileURL('/es-modules/file.unknown')}'`, | ||
| 31 | + `import ${JSON.stringify(fixtures.fileURL('/es-modules/file.unknown'))}`, | ||
| 32 | 32 | ]); | |
| 33 | 33 | ||
| 34 | 34 | assert.match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/); | |
@@ -142,7 +142,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => { | |||
| 142 | 142 | `import assert from 'node:assert'; | |
| 143 | 143 | await Promise.allSettled([ | |
| 144 | 144 | import('nonexistent/file.mjs'), | |
| 145 | - import('${fixtures.fileURL('/es-modules/file.unknown')}'), | ||
| 145 | + import(${JSON.stringify(fixtures.fileURL('/es-modules/file.unknown'))}), | ||
| 146 | 146 | import('esmHook/badReturnVal.mjs'), | |
| 147 | 147 | import('esmHook/format.false'), | |
| 148 | 148 | import('esmHook/format.true'), | |
@@ -170,7 +170,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => { | |||
| 170 | 170 | '--input-type=module', | |
| 171 | 171 | '--eval', | |
| 172 | 172 | `import assert from 'node:assert'; | |
| 173 | - await import('${fixtures.fileURL('/es-module-loaders/js-as-esm.js')}') | ||
| 173 | + await import(${JSON.stringify(fixtures.fileURL('/es-module-loaders/js-as-esm.js'))}) | ||
| 174 | 174 | .then((parsedModule) => { | |
| 175 | 175 | assert.strictEqual(typeof parsedModule, 'object'); | |
| 176 | 176 | assert.strictEqual(parsedModule.namedExport, 'named-export'); | |
@@ -191,7 +191,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => { | |||
| 191 | 191 | '--input-type=module', | |
| 192 | 192 | '--eval', | |
| 193 | 193 | `import assert from 'node:assert'; | |
| 194 | - await import('${fixtures.fileURL('/es-modules/file.ext')}') | ||
| 194 | + await import(${JSON.stringify(fixtures.fileURL('/es-modules/file.ext'))}) | ||
| 195 | 195 | .then((parsedModule) => { | |
| 196 | 196 | assert.strictEqual(typeof parsedModule, 'object'); | |
| 197 | 197 | const { default: defaultExport } = parsedModule; | |
@@ -258,7 +258,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => { | |||
| 258 | 258 | '--input-type=module', | |
| 259 | 259 | '--eval', | |
| 260 | 260 | `import assert from 'node:assert'; | |
| 261 | - await import('${fixtures.fileURL('/es-modules/stateful.mjs')}') | ||
| 261 | + await import(${JSON.stringify(fixtures.fileURL('/es-modules/stateful.mjs'))}) | ||
| 262 | 262 | .then(({ default: count }) => { | |
| 263 | 263 | assert.strictEqual(count(), 1); | |
| 264 | 264 | });`, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ const common = require('../common'); | |||
| 4 | 4 | const assert = require('assert'); | |
| 5 | 5 | const fs = require('fs'); | |
| 6 | 6 | const path = require('path'); | |
| 7 | + const { pathToFileURL } = require('url'); | ||
| 7 | 8 | ||
| 8 | 9 | const tmpdir = require('../common/tmpdir'); | |
| 9 | 10 | tmpdir.refresh(); | |
@@ -40,7 +41,7 @@ function handler(err, folder) { | |||
| 40 | 41 | ||
| 41 | 42 | // Test with URL object | |
| 42 | 43 | { | |
| 43 | - tmpdir.url = new URL(`file://${tmpdir.path}`); | ||
| 44 | + tmpdir.url = pathToFileURL(tmpdir.path); | ||
| 44 | 45 | const urljoin = (base, path) => new URL(path, base); | |
| 45 | 46 | ||
| 46 | 47 | const tmpFolder = fs.mkdtempSync(urljoin(tmpdir.url, 'foo.')); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,7 +58,7 @@ checkStack(err.stack); | |||
| 58 | 58 | // Verify that the stack is only decorated once for uncaught exceptions. | |
| 59 | 59 | const args = [ | |
| 60 | 60 | '-e', | |
| 61 | - `require('${badSyntaxPath}')`, | ||
| 61 | + `require(${JSON.stringify(badSyntaxPath)})`, | ||
| 62 | 62 | ]; | |
| 63 | 63 | const result = spawnSync(process.argv[0], args, { encoding: 'utf8' }); | |
| 64 | 64 | checkStack(result.stderr); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,6 @@ child.on('exit', common.mustCall(() => { | |||
| 19 | 19 | ||
| 20 | 20 | child.stdin.write('const isObject = (obj) => obj.constructor === Object;\n'); | |
| 21 | 21 | child.stdin.write('isObject({});\n'); | |
| 22 | - child.stdin.write(`require('${fixture}').isObject({});\n`); | ||
| 22 | + child.stdin.write(`require(${JSON.stringify(fixture)}).isObject({});\n`); | ||
| 23 | 23 | child.stdin.write('.exit'); | |
| 24 | 24 | child.stdin.end(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,7 +22,7 @@ fs.writeFileSync(fakeModulePath, '', 'utf8'); | |||
| 22 | 22 | ||
| 23 | 23 | stream.on('open', () => { | |
| 24 | 24 | spawnSync(process.execPath, { | |
| 25 | - input: `require("${fakeModulePath.replace(/\\/g, '/')}")`, | ||
| 25 | + input: `require(${JSON.stringify(fakeModulePath)})`, | ||
| 26 | 26 | stdio: ['pipe', 'pipe', stream] | |
| 27 | 27 | }); | |
| 28 | 28 | const stderr = fs.readFileSync(stderrOutputPath, 'utf8').trim(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ const { isMainThread } = require('worker_threads'); | |||
| 7 | 7 | ||
| 8 | 8 | if (isMainThread) { | |
| 9 | 9 | const CODE = 'const { Worker } = require(\'worker_threads\'); ' + | |
| 10 | - `new Worker('${__filename.replace(/\\/g, '/')}', { name: 'foo' })`; | ||
| 10 | + `new Worker(${JSON.stringify(__filename)}, { name: 'foo' })`; | ||
| 11 | 11 | const FILE_NAME = 'node_trace.1.log'; | |
| 12 | 12 | const tmpdir = require('../common/tmpdir'); | |
| 13 | 13 | tmpdir.refresh(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ const { isMainThread } = require('worker_threads'); | |||
| 7 | 7 | ||
| 8 | 8 | if (isMainThread) { | |
| 9 | 9 | const CODE = 'const { Worker } = require(\'worker_threads\'); ' + | |
| 10 | - `new Worker('${__filename.replace(/\\/g, '/')}')`; | ||
| 10 | + `new Worker(${JSON.stringify(__filename)})`; | ||
| 11 | 11 | const FILE_NAME = 'node_trace.1.log'; | |
| 12 | 12 | const tmpdir = require('../common/tmpdir'); | |
| 13 | 13 | tmpdir.refresh(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,6 +7,7 @@ import { describe, it } from 'node:test'; | |||
| 7 | 7 | import { spawn } from 'node:child_process'; | |
| 8 | 8 | import { writeFileSync, readFileSync, mkdirSync } from 'node:fs'; | |
| 9 | 9 | import { inspect } from 'node:util'; | |
| 10 | + import { pathToFileURL } from 'node:url'; | ||
| 10 | 11 | import { createInterface } from 'node:readline'; | |
| 11 | 12 | ||
| 12 | 13 | if (common.isIBMi) | |
@@ -188,7 +189,7 @@ console.log("don't show me");`); | |||
| 188 | 189 | it('should watch changes to dependencies - cjs', async () => { | |
| 189 | 190 | const dependency = createTmpFile('module.exports = {};'); | |
| 190 | 191 | const file = createTmpFile(` | |
| 191 | - const dependency = require('${dependency.replace(/\\/g, '/')}'); | ||
| 192 | + const dependency = require(${JSON.stringify(dependency)}); | ||
| 192 | 193 | console.log(dependency); | |
| 193 | 194 | `); | |
| 194 | 195 | const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: dependency }); | |
@@ -206,7 +207,7 @@ console.log(dependency); | |||
| 206 | 207 | it('should watch changes to dependencies - esm', async () => { | |
| 207 | 208 | const dependency = createTmpFile('module.exports = {};'); | |
| 208 | 209 | const file = createTmpFile(` | |
| 209 | - import dependency from 'file://${dependency.replace(/\\/g, '/')}'; | ||
| 210 | + import dependency from ${JSON.stringify(pathToFileURL(dependency))}; | ||
| 210 | 211 | console.log(dependency); | |
| 211 | 212 | `, '.mjs'); | |
| 212 | 213 | const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: dependency }); | |
@@ -276,7 +277,7 @@ console.log(values.random); | |||
| 276 | 277 | ||
| 277 | 278 | it('should not load --import modules in main process', async () => { | |
| 278 | 279 | const file = createTmpFile(); | |
| 279 | - const imported = `file://${createTmpFile('setImmediate(() => process.exit(0));')}`; | ||
| 280 | + const imported = pathToFileURL(createTmpFile('setImmediate(() => process.exit(0));')); | ||
| 280 | 281 | const args = ['--import', imported, file]; | |
| 281 | 282 | const { stderr, stdout } = await runWriteSucceed({ file, watchedFile: file, args }); | |
| 282 | 283 | ||
@@ -318,9 +319,9 @@ console.log(values.random); | |||
| 318 | 319 | it('should watch changes to previously missing ESM dependency', { | |
| 319 | 320 | skip: !supportsRecursive | |
| 320 | 321 | }, async () => { | |
| 321 | - const dependency = path.join(tmpdir.path, `${tmpFiles++}.mjs`); | ||
| 322 | - const relativeDependencyPath = `./${path.basename(dependency)}`; | ||
| 323 | - const dependant = createTmpFile(`import '${relativeDependencyPath}'`, '.mjs'); | ||
| 322 | + const relativeDependencyPath = `./${tmpFiles++}.mjs`; | ||
| 323 | + const dependency = path.join(tmpdir.path, relativeDependencyPath); | ||
| 324 | + const dependant = createTmpFile(`import ${JSON.stringify(relativeDependencyPath)}`, '.mjs'); | ||
| 324 | 325 | ||
| 325 | 326 | await failWriteSucceed({ file: dependant, watchedFile: dependency }); | |
| 326 | 327 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments