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

feat(absolute-path): Allow usage of absolute path #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Empty file modified lib/dts-bundle.js
100644 → 100755
Empty file.
25 changes: 22 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###');
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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
Expand All @@ -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);
}
Expand Down