mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
remove allowImportingTsExtensions and rewriteRelativeImportExtensions
from companion and remove script rewrite-dts-extensions.js
This commit is contained in:
parent
c33fc301a9
commit
2603291203
4 changed files with 1 additions and 46 deletions
|
|
@ -112,7 +112,7 @@
|
|||
"CHANGELOG.md"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "tsc --build tsconfig.build.json && node ./dist/scripts/rewrite-dts-extensions.js",
|
||||
"build": "tsc --build tsconfig.build.json",
|
||||
"deploy": "kubectl apply -f infra/kube/companion-kube.yml",
|
||||
"start": "node ./dist/standalone/start-server.js",
|
||||
"start:dev": "bash start-dev",
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
// We want to be future-proof and allow our code to be run with Node.js directly (erasableSyntaxOnly, rewriteRelativeImportExtensions and allowImportingTsExtensions are all set). However, even though rewriteRelativeImportExtensions is set, it doesn't rewrite import extensions in outputted declaration (d.ts) files. But it's recommended that d.ts files have .js extensions. This is why we need this script.
|
||||
|
||||
function walk(dir: string, out: string[]): void {
|
||||
for (const ent of fs.readdirSync(dir, { withFileTypes: true })) {
|
||||
const p = path.join(dir, ent.name)
|
||||
if (ent.isDirectory()) {
|
||||
walk(p, out)
|
||||
continue
|
||||
}
|
||||
if (ent.isFile() && p.endsWith('.d.ts')) out.push(p)
|
||||
}
|
||||
}
|
||||
|
||||
function rewriteDtsFile(file: string): boolean {
|
||||
const input = fs.readFileSync(file, 'utf8')
|
||||
const output = input.replace(
|
||||
/(['"])(\.{1,2}\/[^'"]+)\.ts\1/g,
|
||||
(_m, quote: string, rel: string) => `${quote}${rel}.js${quote}`,
|
||||
)
|
||||
if (output === input) return false
|
||||
fs.writeFileSync(file, output)
|
||||
return true
|
||||
}
|
||||
|
||||
const distDir = path.resolve(import.meta.dirname, '../../dist')
|
||||
if (!fs.existsSync(distDir)) {
|
||||
// Nothing to do (e.g. running in a context where dist isn't built yet).
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
const files: string[] = []
|
||||
walk(distDir, files)
|
||||
|
||||
let changed = 0
|
||||
for (const file of files) {
|
||||
if (rewriteDtsFile(file)) changed += 1
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`rewrite-dts-extensions: updated ${changed} .d.ts file(s)`)
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"rewriteRelativeImportExtensions": true,
|
||||
"noEmitOnError": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
|
|
|
|||
|
|
@ -19,6 +19,5 @@
|
|||
"checkJs": false,
|
||||
"skipLibCheck": true,
|
||||
"resolveJsonModule": true,
|
||||
"allowImportingTsExtensions": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue