Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add prepare command for local types support #124

Merged
merged 7 commits into from
May 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"dist"
],
"scripts": {
"prepack": "jiti ../src/cli.ts",
"prepack": "JITI_ESM_RESOLVE=1 jiti ../src/cli.ts",
"dev": "nuxi dev playground",
"dev:build": "nuxi build playground",
"dev:prepare": "jiti ../src/cli.ts --stub && nuxi prepare playground"
"dev:prepare": "JITI_ESM_RESOLVE=1 jiti ../src/cli.ts --stub && JITI_ESM_RESOLVE=1 jiti ../src/cli.ts prepare"
},
"dependencies": {
"@nuxt/kit": "^3.5.1"
Expand Down
2 changes: 1 addition & 1 deletion example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "./playground/.nuxt/tsconfig.json"
"extends": "./.nuxt/tsconfig.json"
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"build": "unbuild",
"example:build": "pnpm nuxt-module-build ./example",
"lint": "eslint --ext .ts,.js,.mjs .",
"nuxt-module-build": "jiti ./src/cli.ts",
"nuxt-module-build": "JITI_ESM_RESOLVE=1 jiti ./src/cli.ts",
"prepack": "pnpm build",
"release": "pnpm test && standard-version && git push --follow-tags && npm publish",
"test": "pnpm vitest"
Expand All @@ -36,6 +36,10 @@
"pathe": "^1.1.0",
"unbuild": "^1.2.1"
},
"peerDependencies": {
"@nuxt/kit": "^3.5.0",
"nuxi": "^3.5.0"
danielroe marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@nuxt/kit": "^3.5.1",
"@nuxt/schema": "^3.5.1",
Expand All @@ -45,6 +49,7 @@
"@vitest/coverage-c8": "^0.31.1",
"eslint": "^8.41.0",
"jiti": "^1.18.2",
"nuxi": "^3.5.1",
"nuxt": "^3.5.1",
"standard-version": "^9.5.0",
"vitest": "^0.31.1"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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

16 changes: 12 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@
import mri from 'mri'
import { resolve } from 'pathe'
import { buildModule } from './build'
import { prepareModule } from './prepare'

async function main () {
// TODO: use citty
function main () {
const args = mri(process.argv.slice(2))
const rootDir = resolve(args._[0] || '.')
await buildModule({
rootDir,

if (args._[0] === 'prepare') {
return prepareModule({
rootDir: resolve(args._[1] || '.')
})
}

return buildModule({
rootDir: resolve(args._[0] || '.'),
outDir: args.outDir,
stub: args.stub
})
Expand Down
30 changes: 30 additions & 0 deletions src/prepare.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { resolve } from 'pathe'

export interface PrepareModuleOptions {
rootDir: string
}

export async function prepareModule (options: PrepareModuleOptions) {
const { runCommand } = await import('nuxi')

return runCommand('prepare', [options.rootDir], {
overrides: {
typescript: {
builder: 'shared'
},
imports: {
autoImport: false
},
modules: [
resolve(options.rootDir, './src/module'),
function (_options, nuxt) {
nuxt.hooks.hook('app:templates', (app) => {
for (const template of app.templates) {
template.write = true
}
})
}
]
}
})
}