diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 62391c3..b66a2b4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,10 +10,10 @@ jobs: build-deploy: runs-on: ubuntu-18.04 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: - node-version: 14 + node-version: 16 - run: npm install - run: npm run build @@ -34,18 +34,17 @@ jobs: - name: Create Tag id: create_tag - uses: jaywcjlove/create-tag-action@v1.2.1 + uses: jaywcjlove/create-tag-action@v1.3.8 with: - token: ${{ secrets.GITHUB_TOKEN }} package-path: ./package.json - name: Generate Changelog id: changelog - uses: jaywcjlove/changelog-generator@v1.4.6 + uses: jaywcjlove/changelog-generator@v1.5.7 with: token: ${{ secrets.GITHUB_TOKEN }} head-ref: ${{steps.create_tag.outputs.version}} - filter-author: (小弟调调™|Renovate Bot) + filter-author: (小弟调调™|dependabot|renovate\\[bot\\]|dependabot\\[bot\\]|Renovate Bot) filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}' - name: Create Release diff --git a/README.md b/README.md index d8c43da..0004597 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Add a banner to a string. Get one-line/multi-line comment banner based on packag ## Install -Install with npm: +This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): Node 14+ is needed to use it and it must be `import` instead of `require`. ```bash npm install bannerjs --save diff --git a/bin/cli.js b/bin/cli.js index e964b5b..09ac379 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,4 +1,5 @@ #!/usr/bin/env node -const bannerjs = require('../lib'); -bannerjs.run(); \ No newline at end of file +import { run } from '../lib/index.js'; + +run(); \ No newline at end of file diff --git a/package.json b/package.json index c9d8439..14b97a6 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,14 @@ "version": "2.1.0", "description": "Get one-line/multi-line comment banner based on package.json.", "homepage": "https://jaywcjlove.github.io/bannerjs/", - "main": "lib/index.js", "bin": { "bannerjs": "./bin/cli.js" }, "author": "kenny wang ", "license": "MIT", + "type": "module", + "exports": "./index.js", + "types": "./index.d.ts", "scripts": { "start": "node lib/index.js", "watch": "tsbb watch --disable-babel", @@ -28,6 +30,9 @@ "src", "lib" ], + "engines": { + "node": ">=14.16" + }, "keywords": [ "comment", "banner", @@ -41,10 +46,13 @@ "coverageReporters": [ "lcov", "json-summary" - ] + ], + "moduleNameMapper": { + "^(\\.{1,2}/.*)\\.js$": "$1" + } }, "devDependencies": { - "types-package-json": "2.0.39", - "tsbb": "3.3.7" + "types-package-json": "^2.0.39", + "tsbb": "^3.7.6" } } diff --git a/src/cli.ts b/src/cli.ts index 98a4975..d3d9885 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,7 +1,7 @@ #!/usr/bin/env node import { createReadStream, createWriteStream } from 'fs'; -import { onebanner, multibanner } from './'; +import { onebanner, multibanner } from './index.js'; export function run() { let args = process.argv.slice(2) diff --git a/src/index.ts b/src/index.ts index 15ba525..457509e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,14 +1,15 @@ -import path from 'path'; +import path from 'node:path'; +import fs from 'node:fs'; import { PackageJson } from 'types-package-json'; -export * from './cli'; +export * from './cli.js'; /** * Get package.json Object */ export function getPackage(rootPath: string = process.cwd()): PackageJson { const pkgPath = path.resolve(rootPath, 'package.json'); - const pkg: PackageJson = require(pkgPath); + const pkg: PackageJson = JSON.parse(fs.readFileSync(pkgPath).toString()); pkg.author = pkg.author; if (pkg.author && typeof pkg.author === 'object' && pkg.author.name) { pkg.author = pkg.author.name; @@ -51,10 +52,12 @@ export function multibanner(option?: PackageJson) { return [ '/**!', '\n *', bn.name, bn.version && `v${bn.version}`, - '\n *', bn.description, + bn.description && `\n * ${bn.description}`, '\n *', `\n * Copyright (c) ${new Date().getFullYear()}`, bn.author, - '\n *', bn.homepage, + '\n *', bn.repository && bn.repository.url && bn.repository.url, + '\n *', + bn.homepage && `\n * @website: ${bn.homepage}\n`, '\n *', bn.license && `Licensed under the ${bn.license} license`, '\n */\n' ].filter(Boolean).join(' '); diff --git a/tsconfig.json b/tsconfig.json index 1968f11..513a9f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { - "module": "commonjs", + "module": "ESNext", + "target": "ESNext", "esModuleInterop": true, "declaration": true, - "target": "es2017", "noImplicitAny": true, "resolveJsonModule": true, "moduleResolution": "node",