-
-
Notifications
You must be signed in to change notification settings - Fork 671
Add node module resolution by default and use --path for custom package locations #594
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
Changes from 18 commits
b8e8ee1
c161742
ff91130
a380ed4
277853e
1dae71a
ef9ebdf
0c42af4
af33db0
cd875dc
6ffb5ff
5869b57
b9a29b7
0e3f1a8
671d49c
7d4e478
deb8942
92e03e5
29ac93e
9b8a1d3
79c08f2
84d2429
e5beacf
117ce01
c7f6ad0
1c86edc
edcf1a0
78907a1
50c2342
1b0c4d7
aad9ed2
9f42e76
df4f0df
aa92094
f36d31d
915761c
fad255a
8db83c6
4dba3d8
1795bca
204791e
9aa137b
55b7f05
02d847a
c7496c2
87b6b5f
bffa751
78a84b3
afe3276
040fe22
e4ca804
1e29ad2
4a53df2
ed7eb64
2c94848
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ node_modules/ | |
out/ | ||
raw/ | ||
.history | ||
|
||
tests/packages/lerna-debug\.log |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -228,6 +228,9 @@ exports.main = function main(argv, options, callback) { | |
|
||
// Begin parsing | ||
var parser = null; | ||
|
||
//maps package names to parent directory | ||
let packages = new Map(); | ||
|
||
// Include library files | ||
Object.keys(exports.libraryFiles).forEach(libPath => { | ||
|
@@ -261,6 +264,7 @@ exports.main = function main(argv, options, callback) { | |
let libText = readFile(libPath, libDir); | ||
if (libText === null) return callback(Error("Library file '" + libPath + "' not found.")); | ||
stats.parseCount++; | ||
exports.libraryFiles[libPath.replace(/\.ts$/, "")] = libText | ||
stats.parseTime += measure(() => { | ||
parser = assemblyscript.parseFile( | ||
libText, | ||
|
@@ -342,7 +346,62 @@ exports.main = function main(argv, options, callback) { | |
} | ||
} | ||
} | ||
if (sourceText == null) { | ||
/* | ||
In this case the library wasn't found so we check paths | ||
*/ | ||
if (sourceText == null && args.path) { | ||
writeStdout(`Looking for ${sourcePath}\n`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should go to stderr - stdout might be module output There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay will change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess that should also be the case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general I think that the debugging might help now to implement the feature, but I'm skeptical that it deserves actual compiler options that nobody will ever use, unless debugging the feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well typescript has the option and I did need a way to debug it. I'm not attached though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, hiding these behind an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I add that now or do a future PR? |
||
for (let _path of args.path) { | ||
let _package = sourcePath.replace(/\~lib\/([^\/]*).*/, `$1`); | ||
if (args.traceResolution) { | ||
writeStdout(`in ${_path}`); | ||
} | ||
let ascMain = (() => { | ||
if (packages.has(_package)){ | ||
return packages.get(_package); | ||
} | ||
let p = path.join(_path, _package, "package.json"); | ||
let res = readFile(p, baseDir); | ||
if (res){ | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let mainFile = JSON.parse(res).ascMain | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (mainFile){ | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let newPackage = mainFile.replace(/(.*)\/index\.ts/, '$1'); | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
packages.set(_package, newPackage); | ||
return newPackage; | ||
} | ||
} | ||
return "assembly"; | ||
})() | ||
let realPath = (_p) => { | ||
return _p.replace(/\~lib\/([^/]*)\/(.*)/, `${_path}/$1/${ascMain}/$2`); | ||
} | ||
const plainName = sourcePath; | ||
const indexName = sourcePath + "/index"; | ||
sourceText = readFile(realPath(plainName) + ".ts", baseDir); | ||
if (sourceText !== null) { | ||
sourcePath = plainName + ".ts"; | ||
} else { | ||
sourceText = readFile(realPath(indexName) + ".ts", baseDir); | ||
if (sourceText !== null) { | ||
sourcePath = indexName + ".ts"; | ||
} | ||
} | ||
if (sourceText !== null) { | ||
if (args.traceResolution) { | ||
writeStdout(` -> Found at ${realPath(sourcePath)}\n`); | ||
} | ||
let newPath = path.join(_path, _package, "node_modules"); | ||
if (!args.path.includes(newPath)){ | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
args.path.push(newPath); | ||
} | ||
break; | ||
} | ||
if (args.traceResolution) { | ||
writeStdout('\n'); | ||
} | ||
} | ||
} | ||
if (sourceText == null){ | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return callback(Error("Import file '" + sourcePath + ".ts' not found.")); | ||
} | ||
stats.parseCount++; | ||
|
@@ -418,6 +477,12 @@ exports.main = function main(argv, options, callback) { | |
// Finish parsing | ||
const program = assemblyscript.finishParsing(parser); | ||
|
||
// Print files and exit if listFiles | ||
if (args.listFiles) { | ||
writeStdout(program.sources.map(s => s.normalizedPath).join("\n") + "\n"); | ||
callback(null); | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// Set up optimization levels | ||
var optimizeLevel = 0; | ||
var shrinkLevel = 0; | ||
|
@@ -718,11 +783,13 @@ exports.main = function main(argv, options, callback) { | |
return callback(null); | ||
|
||
function readFileNode(filename, baseDir) { | ||
let dir = baseDir || "/" | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let name = path.resolve(path.join(dir, filename)); | ||
willemneal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try { | ||
let text; | ||
stats.readCount++; | ||
stats.readTime += measure(() => { | ||
text = fs.readFileSync(path.join(baseDir, filename), { encoding: "utf8" }); | ||
text = fs.readFileSync(name, { encoding: "utf8" }); | ||
}); | ||
return text; | ||
} catch (e) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var cp = require('child_process') | ||
|
||
// Determine OS and set command accordingly | ||
const cmd = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; | ||
|
||
cp.spawn(cmd, ['i'], { env: process.env, cwd: __dirname, stdio: 'inherit' }) | ||
.on("error", () => exit(1)) | ||
.on("close", (code, signal) => { | ||
if (code != 0 ){ | ||
exit(1); | ||
} | ||
cp.spawn(cmd, ['run', 'test'], { env: process.env, cwd: __dirname, stdio: 'inherit' }) | ||
.on("error", () => exit(1)) | ||
.on("close", (code, signal) => { | ||
if (code != 0 ){ | ||
exit(1); | ||
} | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"packages": [ | ||
"packages/*" | ||
], | ||
"version": "0.0.0" | ||
} |
Uh oh!
There was an error while loading. Please reload this page.