|
| 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