-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a14674c
commit 27d8c8a
Showing
6 changed files
with
112 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,68 @@ | ||
const lex = require('bare-module-lexer') | ||
|
||
exports.module = require('bare-module-resolve').module | ||
exports.addon = require('bare-addon-resolve').addon | ||
|
||
exports.default = function resolve (entry, parentURL, opts) { | ||
if (entry.type & lex.constants.ADDON) { | ||
return exports.addon(entry.specifier, parentURL, opts) | ||
} | ||
|
||
return exports.module(entry.specifier, parentURL, opts) | ||
} | ||
|
||
exports.bare = function resolve (entry, parentURL, opts = {}) { | ||
const runtime = require('#runtime') | ||
|
||
const { | ||
platform = runtime.platform, | ||
arch = runtime.arch, | ||
simulator = false | ||
} = opts | ||
|
||
let extensions | ||
let conditions = ['bare', 'node', platform, arch] | ||
|
||
if (simulator) conditions = [...conditions, 'simulator'] | ||
|
||
if (entry.type & lex.constants.ADDON) { | ||
extensions = ['.bare', '.node'] | ||
conditions = ['addon', ...conditions] | ||
|
||
return exports.addon(entry.specifier, parentURL, { extensions, conditions, ...opts }) | ||
} | ||
|
||
if (entry.type & lex.constants.ASSET) { | ||
conditions = ['asset', ...conditions] | ||
} else { | ||
extensions = ['.js', '.cjs', '.mjs', '.json', '.bare', '.node'] | ||
|
||
if (entry.type & lex.constants.REQUIRE) { | ||
conditions = ['require', ...conditions] | ||
} else if (entry.type & lex.constants.IMPORT) { | ||
conditions = ['import', ...conditions] | ||
} | ||
} | ||
|
||
return exports.module(entry.specifier, parentURL, { extensions, conditions, ...opts }) | ||
} | ||
|
||
exports.node = function resolve (entry, parentURL, opts) { | ||
let extensions | ||
let conditions | ||
|
||
if (entry.type & lex.constants.ADDON) { | ||
extensions = ['.node'] | ||
|
||
return exports.addon(entry.specifier, parentURL, { extensions, conditions, ...opts }) | ||
} | ||
|
||
if (entry.type & lex.constants.REQUIRE) { | ||
extensions = ['.js', '.json', '.node'] | ||
conditions = ['node', 'require'] | ||
} else if (entry.type & lex.constants.IMPORT) { | ||
conditions = ['node', 'import'] | ||
} | ||
|
||
return exports.module(entry.specifier, parentURL, { extensions, conditions, ...opts }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* global Bare */ | ||
exports.platform = Bare.platform | ||
exports.arch = Bare.arch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
exports.platform = process.platform | ||
exports.arch = process.arch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters