Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resolve-extension-order #142

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/esbuild/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ func parseArgs(fs fs.FS, rawArgs []string) (argsObject, error) {
case strings.HasPrefix(arg, "--sourcefile="):
args.bundleOptions.SourceFile = arg[len("--sourcefile="):]

case strings.HasPrefix(arg, "--resolve-extension-order="):
args.resolveOptions.ExtensionOrder = strings.Split(arg[len("--resolve-extension-order="):], ",")

case strings.HasPrefix(arg, "--error-limit="):
value, err := strconv.Atoi(arg[len("--error-limit="):])
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions npm/esbuild/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function pushCommonFlags(flags, options) {

if (options.sourcefile) flags.push(`--sourcefile=${options.sourcefile}`);
if (options.target) flags.push(`--target=${options.target}`);
if (options.resolve && options.resolve.extensionOrder) flags.push(`--resolve-extension-order=${options.resolve.extensionOrder.join(',')}`);

if (options.minify) flags.push('--minify');
if (options.minifySyntax) flags.push('--minify-syntax');
Expand Down
14 changes: 14 additions & 0 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const assert = require('assert')
const path = require('path')
const util = require('util')
const fs = require('fs')
const { execSync } = require('child_process');

const repoDir = path.dirname(__dirname)
const testDir = path.join(repoDir, 'scripts', '.js-api-tests')
Expand Down Expand Up @@ -44,6 +45,19 @@ let buildTests = {
const json = JSON.parse(Buffer.from(match[1], 'base64').toString())
assert.strictEqual(json.version, 3)
},

async resolveExtensionOrder({esbuild}) {
const input = path.join(testDir, '4-in.js');
const inputBare = path.join(testDir, '4-module.js')
const inputSomething = path.join(testDir, '4-module.something.js')
const output = path.join(testDir, '4-out.js')
await util.promisify(fs.writeFile)(input, 'console.log(require("./4-module").foo)')
await util.promisify(fs.writeFile)(inputBare, 'exports.foo = 321')
await util.promisify(fs.writeFile)(inputSomething, 'exports.foo = 123')

await esbuild.build({ entryPoints: [input], outfile: output, bundle: true, resolve: {extensionOrder: ['.something.js','.js']} })
assert.strictEqual(execSync(`node ${output}`).toString(), "123\n")
}
}

let transformTests = {
Expand Down