From 1bac8661eaaaa9cada080c05b14eba8d67fa3a13 Mon Sep 17 00:00:00 2001 From: Justin Rahardjo Date: Mon, 23 Oct 2017 16:46:41 +1000 Subject: [PATCH 1/2] feat(absolute-path): Allow usage of absolute path --- lib/dts-bundle.js | 0 lib/index.ts | 21 ++++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) mode change 100644 => 100755 lib/dts-bundle.js diff --git a/lib/dts-bundle.js b/lib/dts-bundle.js old mode 100644 new mode 100755 diff --git a/lib/index.ts b/lib/index.ts index 6e744c4..477bdd2 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -701,7 +701,7 @@ export function bundle(options: Options): BundleResult { assert(moduleName); const impPath = path.resolve(path.dirname(file), moduleName); - + // filename (i.e. starts with a dot, slash or windows drive letter) if (fileExp.test(moduleName)) { // TODO: some module replacing is handled here, whereas the rest is @@ -719,6 +719,25 @@ export function bundle(options: Options): BundleResult { } trace(' - import relative %s (%s)', moduleName, full); + pushUnique(res.relativeImports, full); + res.importLineRef.push(modLine); + // If the path given was an absolute path + } else if (fs.existsSync(path.join(baseDir, moduleName)) + || fs.existsSync(path.join(baseDir, moduleName + '.d.ts'))) { + + const newImpPath = path.join(baseDir, moduleName); + let modLine: ModLine = { + original: lead + quote + getExpName(newImpPath) + trail + }; + res.lines.push(modLine); + + let full = path.resolve(path.dirname(baseDir), newImpPath); + // If full is not an existing file, then let's assume the extension .d.ts + if(!fs.existsSync(full) || fs.existsSync(full + '.d.ts')) { + full += '.d.ts'; + } + trace(' - import relative %s (%s)', moduleName, full); + pushUnique(res.relativeImports, full); res.importLineRef.push(modLine); } From 2cb286e438f8528a1d934b510f12ae38461a96f3 Mon Sep 17 00:00:00 2001 From: Justin Rahardjo Date: Mon, 23 Oct 2017 16:53:06 +1000 Subject: [PATCH 2/2] Updated to fix test (fs filesync change of api) --- lib/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 477bdd2..e07dc34 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -183,7 +183,7 @@ export function bundle(options: Options): BundleResult { mainFileContent += generatedLine + "\n"; }); mainFile = path.resolve(baseDir, "dts-bundle.tmp." + exportName + ".d.ts"); - fs.writeFileSync(mainFile, mainFileContent, 'utf8'); + fs.writeFileSync(mainFile, mainFileContent, { encoding: 'utf8' }); } trace('\n### find typings ###'); @@ -424,7 +424,7 @@ export function bundle(options: Options): BundleResult { } } - fs.writeFileSync(outFile, content, 'utf8'); + fs.writeFileSync(outFile, content, { encoding: 'utf8' }); bundleResult.emitted = true; } else { warning(" XXX Not emit due to exist files not found.")