Skip to content

Commit

Permalink
fix: use declare keyword in the .d.ts files (#10)
Browse files Browse the repository at this point in the history
The dts-bundle project is not maintained anymore. There is a PR to fix an issue but no-one merges it. I could merge it as I'm part of the TypeStrong organization but I don't have a publish access.  To overcome this blocker, I've copied the package and applied the fix. I didn't found any maintained package that could inline typings as dts-bundle does.

✅ Closes: #8
  • Loading branch information
piotr-oles authored Oct 8, 2020
1 parent f8ab53e commit a78a39c
Show file tree
Hide file tree
Showing 15 changed files with 1,040 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
lib
# don't lint nyc coverage output
coverage
# don't lint patches as they are copy-pasted packages
patches
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ $RECYCLE.BIN/
*.lnk

# Artifacts
lib
dist
packages/**/lib
packages/**/dist
coverage
*.tsbuildinfo

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"node": ">= 8"
},
"scripts": {
"postinstall": "lerna bootstrap",
"postinstall": "lerna bootstrap && cd patches/dts-bundle && yarn",
"build": "lerna run build",
"release": "auto shipit",
"precommit": "lint-staged && yarn build && yarn test",
Expand Down Expand Up @@ -55,7 +55,6 @@
"@typescript-eslint/parser": "^2.27.0",
"auto": "^9.26.8",
"commitlint": "^8.3.5",
"dts-bundle": "^0.7.3",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/ast/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
"build:lib": "tsc -b tsconfig.json",
"build:dist": "rollup -c && dts-bundle --name \"@rsql/ast\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build:dist": "rollup -c && node ../../patches/dts-bundle/index.js --name \"@rsql/ast\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
"build:lib": "tsc -b tsconfig.json",
"build:dist": "rollup -c && dts-bundle --name \"@rsql/builder\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build:dist": "rollup -c && node ../../patches/dts-bundle/index.js --name \"@rsql/builder\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/emitter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
"build:lib": "tsc -b tsconfig.json",
"build:dist": "rollup -c && dts-bundle --name \"@rsql/emitter\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build:dist": "rollup -c && node ../../patches/dts-bundle/index.js --name \"@rsql/emitter\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"scripts": {
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
"build:lib": "tsc -b tsconfig.json",
"build:dist": "rollup -c && dts-bundle --name \"@rsql/parser\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build:dist": "rollup -c && node ../../patches/dts-bundle/index.js --name \"@rsql/parser\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
},
"engines": {
Expand Down
22 changes: 22 additions & 0 deletions patches/dts-bundle/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2014 Bart van der Schoor

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions patches/dts-bundle/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require("./lib/dts-bundle");
112 changes: 112 additions & 0 deletions patches/dts-bundle/lib/dts-bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env node

// Remember remove \r chars at end of lines.

var pkg = require("../package");
var program = require("commander");
var dts = require("./index");
var path = require("path");
var os = require("os");

function mapOptions(argObj) {
var result = argObj.configJson ? require(path.resolve(argObj.configJson)) : {};

var optList = [
"main",
"name",
"baseDir",
"out",
//"newline", // Manual
//"indent", // not implemented
"prefix",
// "separator", not implemented
"externals",
//"exclude", // not implemented
"removeSource",
"verbose",
"referenceExternals",
"emitOnIncludedFileNotFound",
"emitOnNoIncludedFileNotFound",
"outputAsModuleFolder",
"headerPath",
];

optList.forEach(function (optName) {
if (argObj.hasOwnProperty(optName)) result[optName] = argObj[optName];
}, this);

if (argObj.hasOwnProperty("newline")) {
switch (argObj.newline) {
case "unix":
result.newline = "\n";
break;
case "windows":
result.newline = "\r\n";
break;
case "currentOsDefault":
result.newline = os.EOL;
break;
}
}
return result;
}

function callBundle(options) {
if (!options.name || !options.main) {
console.log("'name' and 'main' parameters are required. --help for get option list.");
process.exit(1);
}
return dts.bundle(options);
}

program
.version(pkg.version)
.option(
"--configJson <value>",
"path to json config file. Load it first and override options with additional parameters"
)
.option("--name <value>", "name of module likein package.json *required")
.option("--main <value>", "path to entry-point (see documentation) *required")
.option("--baseDir [value]", "base directory to be used for discovering type declarations")
.option("--out [value]", "path of output file. Is relative from baseDir but you can use absolute paths. ")
.option("--externals", 'include typings outside of the "baseDir" (i.e. like node.d.ts)')
.option(
"--referenceExternals",
'reference external modules as <reference path="..." /> tags *** Experimental, TEST NEEDED'
)
//.option('--exclude ', 'filter to exclude typings, either a RegExp or a callback. match path relative to opts.baseDir')
.option("--removeSource", 'delete all source typings (i.e. "<baseDir>/**/*.d.ts")')
.option(
"--newline [style]",
"newline style to use in output file => unix|windows|currentOsDefault",
/^(unix|windows|currentOsDefault)$/i
)
//.option('--indent', 'indentation to use in output file')
.option("--prefix [value]", "prefix for rewriting module names")
// .option('--separator [value]', 'separator for rewriting module "path" names')
.option("--verbose", "enable verbose mode, prints detailed info about all references and includes/excludes")
.option(
"--emitOnIncludedFileNotFound",
'emit although included files not found. See readme "Files not found" section. '
)
.option(
"--emitOnNoIncludedFileNotFound",
'emit although no included files not found. See readme "Files not found" section. '
)
.option(
"--outputAsModuleFolder",
'output as module folder format (no declare module) . See readme "Module folders" section.'
)
.option("--headerPath [value]", "path to file that contains the header")
.parse(process.argv);

console.log("%s version %s\n%s\n", pkg.name, pkg.version, pkg.description);

var options = mapOptions(program);

var result = callBundle(options);

if (!result.emitted) {
console.log("Result no emitted - use verbose to see details.");
process.exit(1);
}
Loading

0 comments on commit a78a39c

Please sign in to comment.