diff --git a/package-lock.json b/package-lock.json index 90ff097..aad2a37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2491,6 +2491,28 @@ "@esbuild/win32-x64": "0.19.5" } }, + "node_modules/esbuild-node-externals": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/esbuild-node-externals/-/esbuild-node-externals-1.9.0.tgz", + "integrity": "sha512-WV6Ogvl+AZEX3vWAM0UGxqb08l3M73EUeymizKGccUC0iWlF1CwdpkZVu200bSqONamjSV0v22vf4YBahJXs8g==", + "dev": true, + "dependencies": { + "find-up": "^5.0.0", + "tslib": "^2.4.1" + }, + "engines": { + "node": ">=12" + }, + "peerDependencies": { + "esbuild": "0.12 - 0.19" + } + }, + "node_modules/esbuild-node-externals/node_modules/tslib": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==", + "dev": true + }, "node_modules/esbuild/node_modules/@esbuild/android-arm": { "version": "0.19.5", "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.5.tgz", @@ -7632,9 +7654,10 @@ }, "devDependencies": { "esbuild": "^0.19.5", + "esbuild-node-externals": "^1.9.0", "prettier": "2.3.0", "tslib": "2.2.0", - "typescript": "4.6.4" + "typescript": "^5.2" } }, "packages/tailwindcss-language-service/node_modules/lru-cache": { @@ -7662,6 +7685,19 @@ "node": ">=10" } }, + "packages/tailwindcss-language-service/node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "packages/vscode-tailwindcss": { "version": "0.10.1", "license": "MIT", diff --git a/packages/tailwindcss-language-service/package.json b/packages/tailwindcss-language-service/package.json index 294c443..f7dfe8b 100644 --- a/packages/tailwindcss-language-service/package.json +++ b/packages/tailwindcss-language-service/package.json @@ -40,8 +40,9 @@ }, "devDependencies": { "esbuild": "^0.19.5", + "esbuild-node-externals": "^1.9.0", "prettier": "2.3.0", "tslib": "2.2.0", - "typescript": "4.6.4" + "typescript": "^5.2" } } diff --git a/packages/tailwindcss-language-service/scripts/build.mjs b/packages/tailwindcss-language-service/scripts/build.mjs index c130614..74c9f3a 100644 --- a/packages/tailwindcss-language-service/scripts/build.mjs +++ b/packages/tailwindcss-language-service/scripts/build.mjs @@ -1,6 +1,8 @@ -import esbuild from 'esbuild' import path from 'node:path' +import { spawnSync } from 'node:child_process' +import esbuild from 'esbuild' import minimist from 'minimist' +import { nodeExternalsPlugin } from 'esbuild-node-externals' const __dirname = new URL('.', import.meta.url).pathname @@ -9,37 +11,43 @@ const args = minimist(process.argv.slice(2), { }) console.log('- Preparing') -let builds = await Promise.all([ - esbuild.context({ - entryPoints: [path.resolve(__dirname, '../src/index.ts')], - bundle: true, - platform: 'node', - external: [], - outdir: 'dist', - minify: args.minify, +let build = await esbuild.context({ + entryPoints: [path.resolve(__dirname, '../src/index.ts')], + bundle: true, + platform: 'node', + external: [], + outdir: 'dist', + minify: args.minify, - format: 'cjs', - }), + format: 'esm', - esbuild.context({ - entryPoints: [path.resolve(__dirname, '../src/index.ts')], - bundle: true, - platform: 'node', - external: [], - outdir: 'dist', - minify: args.minify, - - format: 'esm', - }), -]) + plugins: [ + nodeExternalsPlugin(), + { + name: 'generate-types', + async setup(build) { + build.onEnd(async (result) => { + // Call the tsc command to generate the types + spawnSync( + 'tsc', + ['--emitDeclarationOnly', '--outDir', path.resolve(__dirname, '../dist')], + { + stdio: 'inherit', + } + ) + }) + }, + }, + ], +}) console.log('- Building') -await Promise.all(builds.map((build) => build.rebuild())) +await build.rebuild() if (args.watch) { console.log('- Watching') - await Promise.all(builds.map((build) => build.watch())) + await build.watch() } else { console.log('- Cleaning up') - await Promise.all(builds.map((build) => build.dispose())) + await build.dispose() } diff --git a/packages/tailwindcss-language-service/tsconfig.json b/packages/tailwindcss-language-service/tsconfig.json index 1cfcc9b..e089ae9 100644 --- a/packages/tailwindcss-language-service/tsconfig.json +++ b/packages/tailwindcss-language-service/tsconfig.json @@ -1,7 +1,7 @@ { "include": ["src", "../../types"], "compilerOptions": { - "module": "esnext", + "module": "NodeNext", "lib": ["ES2020"], "target": "ES2020", "importHelpers": true, @@ -13,7 +13,7 @@ "noUnusedParameters": false, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, - "moduleResolution": "node", + "moduleResolution": "NodeNext", "jsx": "react", "esModuleInterop": true }