Skip to content

Commit

Permalink
fix: Broken json import and missing require.resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Aug 3, 2023
1 parent 694d902 commit 46ce76d
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 76 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
/cli.cjs
/test/fixtures/*
/test/generated/*
# eslint doesn't like json imports
/test/index.js
13 changes: 3 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import process from 'node:process'
import run, * as cli from './src/index.js'
import { basename } from 'node:path'
import { pathToFileURL } from 'node:url'
#!/usr/bin/env node

export default cli
import run from './cli.js'

// Auto-Run the CLI if this file is not imported
if (basename(pathToFileURL(process.argv[1]).href) === 'riot') {
/* c8 ignore next */
run(process.argv)
}
run(process.argv)
86 changes: 37 additions & 49 deletions package-lock.json

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

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"node": ">=18.0.0"
},
"bin": {
"riot": "cli.js"
"riot": "index.js"
},
"scripts": {
"cov": "c8 report --reporter=lcov",
"lint": "eslint ./ && npx prettier --check ./",
"cov-html": "c8 report --reporter=html",
"prepublishOnly": "npm run test && npm run build",
"pretest": "npm run lint",
"pretest": "npm run lint && npm run build",
"build": "rollup -c",
"test": "export RIOT_CLI_IGNORE_EXIT_ERRORS=1; c8 mocha --exit test/index.js"
},
Expand All @@ -33,6 +33,9 @@
],
"files": [
"src",
"index.js",
"cli.js",
"cli.cjs",
"README.md"
],
"devDependencies": {
Expand All @@ -42,7 +45,7 @@
"eslint": "^8.46.0",
"eslint-config-riot": "^4.1.0",
"mocha": "^10.2.0",
"prettier": "^3.0.0"
"prettier": "^3.0.1"
},
"license": "MIT",
"bugs": {
Expand All @@ -52,7 +55,7 @@
"author": "Gianluca Guarini <gianluca.guarini@gmail.com> (http://gianlucaguarini.com/)",
"dependencies": {
"@babel/preset-typescript": "^7.22.5",
"@riotjs/compiler": "^9.0.2",
"@riotjs/compiler": "^9.0.3",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-node-resolve": "^15.1.0",
Expand All @@ -62,7 +65,7 @@
"cumpa": "^2.0.1",
"glob": "^10.3.3",
"optionator": "^0.9.3",
"rollup": "^3.27.0",
"rollup-plugin-riot": "^7.0.0"
"rollup": "^3.27.1",
"rollup-plugin-riot": "^9.0.0"
}
}
18 changes: 15 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'

export default {
input: 'index.js',
input: 'src/index.js',
output: [
{
banner: '#!/usr/bin/env node',
file: 'cli.js',
format: 'es',
},
{
banner: '#!/usr/bin/env node',
file: 'cli.cjs',
format: 'cjs',
},
],
plugins: [
// make sure that the json file gets bundled
json({
preferConst: true,
}),
resolve({
resolveOnly: ['package.json'],
}),
commonjs(),
],
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import help from './help.js'
import optionatorFactory from 'optionator'
import options from './options.js'
import { statSync } from 'node:fs'
import pkg from './pkg.js'
import pkg from '../package.json'
import watch from './watch.js'

const optionator = optionatorFactory(options)
Expand Down
2 changes: 1 addition & 1 deletion src/options.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import pkg from './pkg.js'
import pkg from '../package.json'

export default {
prepend: '\nBuilds .riot files to .js\n\nOptions:',
Expand Down
3 changes: 0 additions & 3 deletions src/pkg.js

This file was deleted.

Loading

0 comments on commit 46ce76d

Please sign in to comment.