Skip to content

Commit 96188eb

Browse files
committed
Merge branch 'alpha' into main
2 parents 1218442 + a3ca72b commit 96188eb

7 files changed

+69
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ npm-debug.log*
99
*.d.ts
1010
*.js.map
1111
!/types/*.d.ts
12+
!/fix-types-for-back-compat.js
1213

1314
# macOS
1415
.DS_Store
@@ -31,4 +32,4 @@ Temporary Items
3132
Thumbs.db
3233
ehthumbs.db
3334
Desktop.ini
34-
$RECYCLE.BIN/
35+
$RECYCLE.BIN/

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/.snyk
99
*.ts
1010
!*.d.ts
11+
/fix-types-for-back-compat.js
1112

1213
# yarn and npm
1314
package-lock.json
@@ -36,4 +37,4 @@ Temporary Items
3637
Thumbs.db
3738
ehthumbs.db
3839
Desktop.ini
39-
$RECYCLE.BIN/
40+
$RECYCLE.BIN/

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ node_modules
33
*.js
44
*.d.ts
55
*.js.map
6-
!/types/*.d.ts
6+
!/types/*.d.ts
7+
!/fix-types-for-back-compat.js

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Module:
5959
Include something like the following in `webpack.config.js`:
6060

6161
```js
62-
const ResolveTypeScriptPlugin = require("resolve-typescript-plugin").default;
62+
const ResolveTypeScriptPlugin = require("resolve-typescript-plugin");
6363

6464
exports = {
6565
module: {

fix-types-for-back-compat.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"use strict";
2+
3+
const typescript = require("typescript");
4+
const fs = require("fs");
5+
6+
const program = typescript.createProgram(["index.d.ts"], {});
7+
const source = program.getSourceFile("index.d.ts");
8+
const printer = typescript.createPrinter();
9+
10+
const fix = context => node => {
11+
const visit = node => {
12+
if (
13+
typescript.isIdentifier(node) &&
14+
node.escapedText === "ResolveTypescriptPluginOptions"
15+
) {
16+
return typescript.factory.createQualifiedName(
17+
typescript.factory.createIdentifier("ResolveTypescriptPlugin"),
18+
typescript.factory.createIdentifier("ResolveTypescriptPluginOptions")
19+
);
20+
} else {
21+
return typescript.visitEachChild(node, visit, context);
22+
}
23+
};
24+
const visitTopLevel = node => {
25+
if (
26+
typescript.isInterfaceDeclaration(node) &&
27+
node.name.escapedText === "ResolveTypescriptPluginOptions"
28+
) {
29+
return typescript.factory.createModuleDeclaration(
30+
[],
31+
[typescript.factory.createModifier(typescript.SyntaxKind.DeclareKeyword)],
32+
typescript.factory.createIdentifier("ResolveTypescriptPlugin"),
33+
typescript.factory.createModuleBlock([node]),
34+
typescript.NodeFlags.Namespace
35+
);
36+
} else {
37+
return typescript.visitEachChild(node, visit, context);
38+
}
39+
};
40+
return typescript.visitEachChild(node, visitTopLevel, context);
41+
};
42+
43+
if (source != null) {
44+
typescript.transform(source, [fix]).transformed.forEach(node => {
45+
if (typescript.isSourceFile(node)) {
46+
fs.writeFileSync("index.d.ts", printer.printFile(node));
47+
}
48+
});
49+
}

index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ type Resolver = NonNullable<ResolveOptions["resolver"]>;
44

55
const pluginName = "ResolveTypescriptPlugin";
66

7-
export interface ResolveTypescriptPluginOptions {
7+
interface ResolveTypescriptPluginOptions {
88
includeNodeModules?: boolean;
99
}
1010

11-
export default class ResolveTypescriptPlugin {
11+
class ResolveTypescriptPlugin {
12+
/** @deprecated For backwards compatibility with versions < v1.2.
13+
* Will be removed in v2.0. */
14+
public static default = ResolveTypescriptPlugin;
15+
1216
private static defaultOptions: ResolveTypescriptPluginOptions = {
1317
includeNodeModules: false
1418
};
@@ -55,3 +59,5 @@ export default class ResolveTypescriptPlugin {
5559
}
5660
}
5761
}
62+
63+
export = ResolveTypescriptPlugin;

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
"bugs": "https://github.com/softwareventures/resolve-typescript-plugin/issues",
1515
"repository": "github:softwareventures/resolve-typescript-plugin",
1616
"license": "ISC",
17+
"exports": {
18+
".": "./index.js"
19+
},
20+
"types": "index.d.ts",
1721
"scripts": {
1822
"fix": "tsc --noEmit && eslint . --fix && prettier --write .",
1923
"lint": "tsc --noEmit && eslint . && prettier --check .",
20-
"prepare": "tsc",
24+
"prepare": "tsc && node ./fix-types-for-back-compat.js",
2125
"semantic-release": "semantic-release",
2226
"test": "ava"
2327
},

0 commit comments

Comments
 (0)