Skip to content

Commit

Permalink
fix #786: avoid absolute paths for disabled modules (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
eelco authored Feb 11, 2021
1 parent e8c7f18 commit 6d4147c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/bundler/snapshots/snapshots_packagejson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var index;
================================================================================
TestPackageJsonBrowserMapModuleDisabled
---------- /Users/user/project/out.js ----------
// (disabled):/Users/user/project/node_modules/node-pkg/index.js
// (disabled):Users/user/project/node_modules/node-pkg/index.js
var require_node_pkg = __commonJS(() => {
});

Expand Down
4 changes: 2 additions & 2 deletions internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ func (r *resolver) resolveWithoutSymlinks(sourceDir string, importPath string, k
if remapped == nil {
// "browser": {"module": false}
if absolute, ok := r.loadNodeModules(importPath, kind, sourceDirInfo); ok {
absolute.Primary = logger.Path{Text: absolute.Primary.Text, Flags: logger.PathDisabled}
absolute.Primary = logger.Path{Text: absolute.Primary.Text, Namespace: "file", Flags: logger.PathDisabled}
if absolute.HasSecondary() {
absolute.Secondary = logger.Path{Text: absolute.Secondary.Text, Flags: logger.PathDisabled}
absolute.Secondary = logger.Path{Text: absolute.Secondary.Text, Namespace: "file", Flags: logger.PathDisabled}
}
return &ResolveResult{PathPair: absolute}
} else {
Expand Down
22 changes: 22 additions & 0 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,28 @@ let buildTests = {
assert.strictEqual(json.sourcesContent[1], content)
},

async sourceMapWithDisabledModule({ esbuild, testDir }) {
const input = path.join(testDir, 'in.js')
const disabled = path.join(testDir, 'node_modules', 'disabled', 'index.js')
const packageJSON = path.join(testDir, 'package.json')
const output = path.join(testDir, 'out.js')
const content = 'exports.foo = require("disabled")'
await mkdirAsync(path.dirname(disabled), { recursive: true })
await writeFileAsync(input, content)
await writeFileAsync(disabled, 'module.exports = 123')
await writeFileAsync(packageJSON, `{"browser": {"disabled": false}}`)
await esbuild.build({ entryPoints: [input], outfile: output, sourcemap: true, bundle: true })
const result = require(output)
assert.strictEqual(result.foo, void 0)
const resultMap = await readFileAsync(output + '.map', 'utf8')
const json = JSON.parse(resultMap)
assert.strictEqual(json.version, 3)
assert.strictEqual(json.sources[0], path.relative(testDir, disabled).split(path.sep).join('/'))
assert.strictEqual(json.sources[1], path.basename(input))
assert.strictEqual(json.sourcesContent[0], '')
assert.strictEqual(json.sourcesContent[1], content)
},

async resolveExtensionOrder({ esbuild, testDir }) {
const input = path.join(testDir, 'in.js');
const inputBare = path.join(testDir, 'module.js')
Expand Down

0 comments on commit 6d4147c

Please sign in to comment.