Skip to content

Commit

Permalink
Tweak build script
Browse files Browse the repository at this point in the history
  • Loading branch information
thecrypticace committed Oct 27, 2023
1 parent df8857b commit 3df6999
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 31 deletions.
38 changes: 37 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/tailwindcss-language-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
62 changes: 35 additions & 27 deletions packages/tailwindcss-language-service/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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,

format: 'cjs',
}),

esbuild.context({
entryPoints: [path.resolve(__dirname, '../src/index.ts')],
bundle: true,
platform: 'node',
external: [],
outdir: 'dist',
minify: args.minify,

format: 'esm',
}),
])
let build = await 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()
}
4 changes: 2 additions & 2 deletions packages/tailwindcss-language-service/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"include": ["src", "../../types"],
"compilerOptions": {
"module": "esnext",
"module": "NodeNext",
"lib": ["ES2020"],
"target": "ES2020",
"importHelpers": true,
Expand All @@ -13,7 +13,7 @@
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"moduleResolution": "NodeNext",
"jsx": "react",
"esModuleInterop": true
}
Expand Down

0 comments on commit 3df6999

Please sign in to comment.