@nuxt/module-builder 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +15 -0
- package/.eslintignore +3 -0
- package/.eslintrc +5 -0
- package/.github/workflows/ci.yml +23 -0
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/build.config.ts +12 -0
- package/dist/chunks/build.mjs +40 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.mjs +15 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.mjs +3 -0
- package/package.json +37 -0
- package/playground/package.json +17 -0
- package/playground/src/custom.ts +1 -0
- package/playground/src/module.ts +5 -0
- package/playground/src/runtime/plugin.ts +4 -0
- package/renovate.json +11 -0
- package/src/build.ts +40 -0
- package/src/cli.ts +17 -0
- package/src/index.ts +1 -0
- package/tsconfig.json +16 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
end_of_line = lf
|
|
5
|
+
insert_final_newline = true
|
|
6
|
+
trim_trailing_whitespace = true
|
|
7
|
+
charset = utf-8
|
|
8
|
+
|
|
9
|
+
[*.js]
|
|
10
|
+
indent_style = space
|
|
11
|
+
indent_size = 2
|
|
12
|
+
|
|
13
|
+
[{package.json,*.yml,*.cjson}]
|
|
14
|
+
indent_style = space
|
|
15
|
+
indent_size = 2
|
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
ci:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v2
|
|
16
|
+
- uses: actions/setup-node@v2
|
|
17
|
+
with:
|
|
18
|
+
node-version: 16
|
|
19
|
+
cache: 'yarn'
|
|
20
|
+
- run: yarn install
|
|
21
|
+
- run: yarn lint
|
|
22
|
+
- run: yarn build
|
|
23
|
+
- run: yarn play
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 - Nuxt Project
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Nuxt Module Builder
|
|
2
|
+
|
|
3
|
+
> Build Nuxt modules using [unjs/unbuild](https://github.com/unjs/unbuild).
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
- Install `@nuxt/module-builder` as a devDependency
|
|
8
|
+
- Use `npx nuxt-build-module` to build module
|
|
9
|
+
|
|
10
|
+
Note: Module structure needs `src/module.ts` and optional `src/runtime/`
|
|
11
|
+
|
|
12
|
+
## Development
|
|
13
|
+
|
|
14
|
+
- Clone this repository
|
|
15
|
+
- Try changes using `yarn play` (it will build `playground/` to `playground/dist/`)
|
|
16
|
+
|
|
17
|
+
## License
|
|
18
|
+
|
|
19
|
+
[MIT](./LICENSE) - Made with 💚
|
package/build.config.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { promises } from 'fs';
|
|
2
|
+
import { resolve } from 'pathe';
|
|
3
|
+
|
|
4
|
+
async function buildModule(rootDir) {
|
|
5
|
+
const { build } = await import('unbuild');
|
|
6
|
+
await build(rootDir, false, {
|
|
7
|
+
declaration: true,
|
|
8
|
+
entries: [
|
|
9
|
+
"src/module",
|
|
10
|
+
{ input: "src/runtime/", outDir: "dist/runtime", ext: "mjs" }
|
|
11
|
+
],
|
|
12
|
+
rollup: {
|
|
13
|
+
emitCJS: false,
|
|
14
|
+
cjsBridge: true
|
|
15
|
+
},
|
|
16
|
+
externals: [
|
|
17
|
+
"@nuxt/schema",
|
|
18
|
+
"@nuxt/schema-edge",
|
|
19
|
+
"@nuxt/kit",
|
|
20
|
+
"@nuxt/kit-edge"
|
|
21
|
+
],
|
|
22
|
+
hooks: {
|
|
23
|
+
async "build:done"(ctx) {
|
|
24
|
+
await writeCJSStub(ctx.options.outDir);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async function writeCJSStub(distDir) {
|
|
30
|
+
const cjsStubFile = resolve(distDir, "module.cjs");
|
|
31
|
+
const cjsStub = `// CommonJS proxy to use native ESM
|
|
32
|
+
module.exports = function(...args) {
|
|
33
|
+
return import('./module.mjs').then(m => m.default.call(this, ...args))
|
|
34
|
+
}
|
|
35
|
+
module.exports.meta = require('../package.json')
|
|
36
|
+
`;
|
|
37
|
+
await promises.writeFile(cjsStubFile, cjsStub, "utf8");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { buildModule as b };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/env node
|
|
2
|
+
import mri from 'mri';
|
|
3
|
+
import { resolve } from 'pathe';
|
|
4
|
+
import { b as buildModule } from './chunks/build.mjs';
|
|
5
|
+
import 'fs';
|
|
6
|
+
|
|
7
|
+
async function main() {
|
|
8
|
+
const args = mri(process.argv.slice(2));
|
|
9
|
+
const rootDir = resolve(args._[0] || ".");
|
|
10
|
+
await buildModule(rootDir);
|
|
11
|
+
}
|
|
12
|
+
main().catch((err) => {
|
|
13
|
+
console.error(err);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
});
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nuxt/module-builder",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.mjs"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"bin": {
|
|
13
|
+
"nuxt-build-module": "./dist/cli.mjs"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "unbuild",
|
|
17
|
+
"cli": "jiti ./src/cli.ts",
|
|
18
|
+
"lint": "eslint --ext .ts,.js,.mjs .",
|
|
19
|
+
"prepack": "yarn build",
|
|
20
|
+
"play": "yarn cli ./playground",
|
|
21
|
+
"release": "yarn test && standard-version && git push --follow-tags && npm publish",
|
|
22
|
+
"test": "yarn lint"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"mri": "^1.2.0",
|
|
26
|
+
"pathe": "^0.2.0",
|
|
27
|
+
"unbuild": "^0.6.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@nuxt/kit": "npm:@nuxt/kit-edge@latest",
|
|
31
|
+
"@nuxtjs/eslint-config-typescript": "^8.0.0",
|
|
32
|
+
"@types/mri": "^1.1.1",
|
|
33
|
+
"eslint": "^8.3.0",
|
|
34
|
+
"jiti": "^1.12.9",
|
|
35
|
+
"standard-version": "^9.3.2"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"private": true,
|
|
3
|
+
"name": "mymodule",
|
|
4
|
+
"main": "./dist/module.cjs",
|
|
5
|
+
"types": "./dist/module.d.ts",
|
|
6
|
+
"build": {
|
|
7
|
+
"entries": [
|
|
8
|
+
"./src/custom"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"require": "./dist/module.cjs",
|
|
14
|
+
"import": "./dist/module.mjs"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// Custom entry
|
package/renovate.json
ADDED
package/src/build.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { promises as fsp } from 'fs'
|
|
2
|
+
import { resolve } from 'pathe'
|
|
3
|
+
|
|
4
|
+
export async function buildModule (rootDir: string) {
|
|
5
|
+
const { build } = await import('unbuild')
|
|
6
|
+
|
|
7
|
+
await build(rootDir, false, {
|
|
8
|
+
declaration: true,
|
|
9
|
+
entries: [
|
|
10
|
+
'src/module',
|
|
11
|
+
{ input: 'src/runtime/', outDir: 'dist/runtime', ext: 'mjs' }
|
|
12
|
+
],
|
|
13
|
+
rollup: {
|
|
14
|
+
emitCJS: false,
|
|
15
|
+
cjsBridge: true
|
|
16
|
+
},
|
|
17
|
+
externals: [
|
|
18
|
+
'@nuxt/schema',
|
|
19
|
+
'@nuxt/schema-edge',
|
|
20
|
+
'@nuxt/kit',
|
|
21
|
+
'@nuxt/kit-edge'
|
|
22
|
+
],
|
|
23
|
+
hooks: {
|
|
24
|
+
async 'build:done' (ctx) {
|
|
25
|
+
await writeCJSStub(ctx.options.outDir)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function writeCJSStub (distDir: string) {
|
|
32
|
+
const cjsStubFile = resolve(distDir, 'module.cjs')
|
|
33
|
+
const cjsStub = `// CommonJS proxy to use native ESM
|
|
34
|
+
module.exports = function(...args) {
|
|
35
|
+
return import('./module.mjs').then(m => m.default.call(this, ...args))
|
|
36
|
+
}
|
|
37
|
+
module.exports.meta = require('../package.json')
|
|
38
|
+
`
|
|
39
|
+
await fsp.writeFile(cjsStubFile, cjsStub, 'utf8')
|
|
40
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/bin/env node
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
import mri from 'mri'
|
|
5
|
+
import { resolve } from 'pathe'
|
|
6
|
+
import { buildModule } from './build'
|
|
7
|
+
|
|
8
|
+
async function main () {
|
|
9
|
+
const args = mri(process.argv.slice(2))
|
|
10
|
+
const rootDir = resolve(args._[0] || '.')
|
|
11
|
+
await buildModule(rootDir)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
main().catch((err) => {
|
|
15
|
+
console.error(err)
|
|
16
|
+
process.exit(1)
|
|
17
|
+
})
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './build'
|
package/tsconfig.json
ADDED