Skip to content

Commit 4b96311

Browse files
Uzlopakanonrig
authored andcommitted
test typescript interop
1 parent 93c9da4 commit 4b96311

File tree

7 files changed

+152
-7
lines changed

7 files changed

+152
-7
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Typescript Interop
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
ts-interop-test:
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
matrix:
20+
package-json-type:
21+
- commonjs
22+
- module
23+
tsconfig-json-module:
24+
- CommonJS
25+
- ESNext
26+
- Node16
27+
- Nodenext
28+
tsconfig-json-module-resolution:
29+
- Node
30+
- Node16
31+
- Nodenext
32+
exclude:
33+
- package-json-type: commonjs
34+
tsconfig-json-module: ESNext
35+
- package-json-type: module
36+
tsconfig-json-module: CommonJS
37+
- package-json-type: module
38+
tsconfig-json-module: Node16
39+
tsconfig-json-module-resolution: Node
40+
- package-json-type: module
41+
tsconfig-json-module: NodeNext
42+
tsconfig-json-module-resolution: Node
43+
44+
fail-fast: false
45+
46+
steps:
47+
- uses: actions/checkout@v3
48+
with:
49+
persist-credentials: false
50+
- uses: actions/setup-node@v3
51+
with:
52+
node-version: 18
53+
- run: |
54+
npm install --ignore-scripts &&
55+
npm link &&
56+
node scripts/create-ts-interop-test &&
57+
cd test_interop &&
58+
npm i --ignore-scripts &&
59+
npm link fast-querystring &&
60+
npm run test-interop
61+
env:
62+
PACKAGE_JSON_TYPE: ${{ matrix.package-json-type }}
63+
TSCONFIG_MODULE: ${{ matrix.tsconfig-json-module }}
64+
TSCONFIG_MODULE_RESOLUTION: ${{ matrix.tsconfig-json-module-resolution }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules
22
coverage
33
package-lock.json
4+
test_interop

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ benchmark
66
.idea
77
.github
88
rome.json
9+
scripts
10+
test_interop

lib/index.d.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
declare namespace FastQuerystring {
1+
type FastQueryString = {
2+
stringify(value: Record<string, any>): string;
3+
parse(value: string): Record<string, any>;
4+
};
5+
6+
declare namespace fastQueryString {
27
export function stringify(value: Record<string, any>): string;
38
export function parse(value: string): Record<string, any>;
9+
10+
const fqs: FastQueryString;
11+
export { fqs as default };
412
}
513

6-
export function stringify(value: Record<string, any>): string;
7-
export function parse(value: string): Record<string, any>;
8-
export default FastQuerystring;
14+
export = fastQueryString;

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ const fastQuerystring = {
1616
*/
1717
module.exports = fastQuerystring;
1818
module.exports.default = fastQuerystring;
19+
module.exports.parse = parse;
20+
module.exports.stringify = stringify;

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
"name": "fast-querystring",
33
"version": "1.0.0",
44
"description": "A fast alternative to legacy querystring module",
5-
"main": "lib/index.js",
6-
"type": "commonjs",
7-
"types": "lib/index.d.ts",
5+
"main": "./lib/index.js",
6+
"types": "./lib/index.d.ts",
87
"scripts": {
98
"format": "rome format . --write",
109
"format:ci": "rome ci .",

scripts/create-ts-interop-test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env node
2+
const path = require("path");
3+
const fs = require("fs").promises;
4+
5+
const packageJsonType =
6+
process.argv[2] || process.env.PACKAGE_JSON_TYPE || "commonjs";
7+
const tsconfigModule = process.argv[2] || process.env.TSCONFIG_MODULE || "Node";
8+
const tsconfigModuleResolution =
9+
process.argv[2] || process.env.TSCONFIG_MODULE_RESOLUTION || "Node";
10+
11+
const rootPath = path.join(__dirname, "..");
12+
const testPath = path.join(rootPath, "test_interop");
13+
14+
const indexTs = `import fastQuerystring from 'fast-querystring'
15+
import { stringify, parse } from 'fast-querystring'
16+
import * as fQuerystring from 'fast-querystring'
17+
import { equal } from "assert"
18+
19+
equal(typeof fastQuerystring, 'object')
20+
equal(typeof fastQuerystring.stringify, 'function')
21+
equal(typeof fastQuerystring.parse, 'function')
22+
equal(typeof fQuerystring.stringify, 'function')
23+
equal(typeof fQuerystring.parse, 'function')
24+
equal(typeof stringify, 'function')
25+
equal(typeof parse, 'function')
26+
`;
27+
28+
const tsconfigJson = JSON.stringify(
29+
{
30+
compilerOptions: {
31+
module: tsconfigModule,
32+
moduleResolution: tsconfigModuleResolution,
33+
},
34+
},
35+
null,
36+
2,
37+
);
38+
39+
const packageJson = JSON.stringify(
40+
{
41+
name: "fqs-test",
42+
version: "1.0.0",
43+
description: "",
44+
main: "index.js",
45+
type: packageJsonType,
46+
scripts: {
47+
"test-interop": "tsc -p . && node index.js",
48+
},
49+
keywords: [],
50+
author: "",
51+
license: "ISC",
52+
dependencies: {
53+
"@types/node": "^18.11.10",
54+
typescript: "^4.9.3",
55+
},
56+
},
57+
null,
58+
2,
59+
);
60+
61+
async function main() {
62+
await fs.mkdir(testPath);
63+
await fs.writeFile(path.join(testPath, "package.json"), packageJson);
64+
await fs.writeFile(path.join(testPath, "tsconfig.json"), tsconfigJson);
65+
await fs.writeFile(path.join(testPath, "index.ts"), indexTs);
66+
}
67+
68+
main(process.argv).catch((err) => {
69+
console.error(err);
70+
process.exit(1);
71+
});

0 commit comments

Comments
 (0)