Skip to content

Commit a78a39c

Browse files
authored
fix: use declare keyword in the .d.ts files (#10)
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
1 parent f8ab53e commit a78a39c

File tree

15 files changed

+1040
-82
lines changed

15 files changed

+1040
-82
lines changed

.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ node_modules
44
lib
55
# don't lint nyc coverage output
66
coverage
7+
# don't lint patches as they are copy-pasted packages
8+
patches

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ $RECYCLE.BIN/
8585
*.lnk
8686

8787
# Artifacts
88-
lib
89-
dist
88+
packages/**/lib
89+
packages/**/dist
9090
coverage
9191
*.tsbuildinfo
9292

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"node": ">= 8"
1111
},
1212
"scripts": {
13-
"postinstall": "lerna bootstrap",
13+
"postinstall": "lerna bootstrap && cd patches/dts-bundle && yarn",
1414
"build": "lerna run build",
1515
"release": "auto shipit",
1616
"precommit": "lint-staged && yarn build && yarn test",
@@ -55,7 +55,6 @@
5555
"@typescript-eslint/parser": "^2.27.0",
5656
"auto": "^9.26.8",
5757
"commitlint": "^8.3.5",
58-
"dts-bundle": "^0.7.3",
5958
"eslint": "^6.8.0",
6059
"eslint-config-prettier": "^6.10.1",
6160
"eslint-plugin-prettier": "^3.1.2",

packages/ast/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
2323
"build:lib": "tsc -b tsconfig.json",
24-
"build:dist": "rollup -c && dts-bundle --name \"@rsql/ast\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
24+
"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",
2525
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
2626
},
2727
"engines": {

packages/builder/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
2323
"build:lib": "tsc -b tsconfig.json",
24-
"build:dist": "rollup -c && dts-bundle --name \"@rsql/builder\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
24+
"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",
2525
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
2626
},
2727
"engines": {

packages/emitter/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
2323
"build:lib": "tsc -b tsconfig.json",
24-
"build:dist": "rollup -c && dts-bundle --name \"@rsql/emitter\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
24+
"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",
2525
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
2626
},
2727
"engines": {

packages/parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"build:clean": "rm -rf ./lib && rm -f tsconfig.tsbuildinfo && rm -rf ./dist",
2323
"build:lib": "tsc -b tsconfig.json",
24-
"build:dist": "rollup -c && dts-bundle --name \"@rsql/parser\" --main lib/index.d.ts --out ../dist/index.d.ts --outputAsModuleFolder && prettier --write ./dist",
24+
"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",
2525
"build": "yarn build:clean && yarn build:lib && yarn build:dist"
2626
},
2727
"engines": {

patches/dts-bundle/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2014 Bart van der Schoor
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

patches/dts-bundle/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require("./lib/dts-bundle");
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env node
2+
3+
// Remember remove \r chars at end of lines.
4+
5+
var pkg = require("../package");
6+
var program = require("commander");
7+
var dts = require("./index");
8+
var path = require("path");
9+
var os = require("os");
10+
11+
function mapOptions(argObj) {
12+
var result = argObj.configJson ? require(path.resolve(argObj.configJson)) : {};
13+
14+
var optList = [
15+
"main",
16+
"name",
17+
"baseDir",
18+
"out",
19+
//"newline", // Manual
20+
//"indent", // not implemented
21+
"prefix",
22+
// "separator", not implemented
23+
"externals",
24+
//"exclude", // not implemented
25+
"removeSource",
26+
"verbose",
27+
"referenceExternals",
28+
"emitOnIncludedFileNotFound",
29+
"emitOnNoIncludedFileNotFound",
30+
"outputAsModuleFolder",
31+
"headerPath",
32+
];
33+
34+
optList.forEach(function (optName) {
35+
if (argObj.hasOwnProperty(optName)) result[optName] = argObj[optName];
36+
}, this);
37+
38+
if (argObj.hasOwnProperty("newline")) {
39+
switch (argObj.newline) {
40+
case "unix":
41+
result.newline = "\n";
42+
break;
43+
case "windows":
44+
result.newline = "\r\n";
45+
break;
46+
case "currentOsDefault":
47+
result.newline = os.EOL;
48+
break;
49+
}
50+
}
51+
return result;
52+
}
53+
54+
function callBundle(options) {
55+
if (!options.name || !options.main) {
56+
console.log("'name' and 'main' parameters are required. --help for get option list.");
57+
process.exit(1);
58+
}
59+
return dts.bundle(options);
60+
}
61+
62+
program
63+
.version(pkg.version)
64+
.option(
65+
"--configJson <value>",
66+
"path to json config file. Load it first and override options with additional parameters"
67+
)
68+
.option("--name <value>", "name of module likein package.json *required")
69+
.option("--main <value>", "path to entry-point (see documentation) *required")
70+
.option("--baseDir [value]", "base directory to be used for discovering type declarations")
71+
.option("--out [value]", "path of output file. Is relative from baseDir but you can use absolute paths. ")
72+
.option("--externals", 'include typings outside of the "baseDir" (i.e. like node.d.ts)')
73+
.option(
74+
"--referenceExternals",
75+
'reference external modules as <reference path="..." /> tags *** Experimental, TEST NEEDED'
76+
)
77+
//.option('--exclude ', 'filter to exclude typings, either a RegExp or a callback. match path relative to opts.baseDir')
78+
.option("--removeSource", 'delete all source typings (i.e. "<baseDir>/**/*.d.ts")')
79+
.option(
80+
"--newline [style]",
81+
"newline style to use in output file => unix|windows|currentOsDefault",
82+
/^(unix|windows|currentOsDefault)$/i
83+
)
84+
//.option('--indent', 'indentation to use in output file')
85+
.option("--prefix [value]", "prefix for rewriting module names")
86+
// .option('--separator [value]', 'separator for rewriting module "path" names')
87+
.option("--verbose", "enable verbose mode, prints detailed info about all references and includes/excludes")
88+
.option(
89+
"--emitOnIncludedFileNotFound",
90+
'emit although included files not found. See readme "Files not found" section. '
91+
)
92+
.option(
93+
"--emitOnNoIncludedFileNotFound",
94+
'emit although no included files not found. See readme "Files not found" section. '
95+
)
96+
.option(
97+
"--outputAsModuleFolder",
98+
'output as module folder format (no declare module) . See readme "Module folders" section.'
99+
)
100+
.option("--headerPath [value]", "path to file that contains the header")
101+
.parse(process.argv);
102+
103+
console.log("%s version %s\n%s\n", pkg.name, pkg.version, pkg.description);
104+
105+
var options = mapOptions(program);
106+
107+
var result = callBundle(options);
108+
109+
if (!result.emitted) {
110+
console.log("Result no emitted - use verbose to see details.");
111+
process.exit(1);
112+
}

0 commit comments

Comments
 (0)