Skip to content

Commit

Permalink
update to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmywarting authored and voxpelli committed Sep 17, 2021
1 parent 5cf1365 commit 2c02104
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 21 deletions.
16 changes: 12 additions & 4 deletions bin/cmd.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/usr/bin/env node
/* eslint-disable no-var, no-eval */

if (process.version.match(/v(\d+)\./)[1] < 4) {
console.error('standardx: Node v4 or greater is required. `standardx` did not run.')
var match = process.version.match(/v(\d+)\.(\d+)/)
var major = parseInt(match[1], 10)
var minor = parseInt(match[2], 10)

if (major >= 12 || (major === 12 && minor >= 20)) {
eval('import("standard-engine")').then(function (standardEngine) {
eval('import("../options.js")').then(function (options) {
standardEngine.cli(options.default)
})
})
} else {
const opts = require('../options')
require('standard-engine').cli(opts)
console.error('standardx: Node 12.20.0 or greater is required. `standardx` did not run.')
}
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/*! standardx. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
const Linter = require('standard-engine').linter
const opts = require('./options')
import standardEngine from 'standard-engine'
import opts from './options.js'

module.exports = new Linter(opts)
const Linter = standardEngine.linter

export default new Linter(opts)
15 changes: 8 additions & 7 deletions options.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
const pkg = require('./package.json')
const stdVersion = require('standard/package.json').version
const stdOpts = require('standard/options.js')
import { readFileSync } from 'node:fs'
import stdOpts from 'standard/options.js'

const opts = Object.assign({}, stdOpts, {
const stdVersion = stdOpts.version
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'))
const baseConfig = JSON.parse(readFileSync(stdOpts.eslintConfig.configFile, 'utf-8'))

export default Object.assign({}, stdOpts, {
bugs: pkg.bugs.url,
cmd: 'standardx',
eslintConfig: {
baseConfig: require('standard/eslintrc.json'),
baseConfig,
useEslintrc: true
},
homepage: pkg.homepage,
tagline: 'Use JavaScript Standard Style (tweaked by standardx)',
version: `${pkg.version} (standard ${stdVersion})`
})

module.exports = opts
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
"bugs": {
"url": "https://github.com/standard/standardx/issues"
},
"type": "module",
"dependencies": {
"standard": "^16.0.1",
"standard-engine": "^14.0.1"
},
"devDependencies": {
"cross-spawn": "^7.0.3",
"tap-spec": "^5.0.0",
"tape": "^5.0.1"
"tape": "^5.3.1"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"homepage": "https://github.com/standard/standardx",
"keywords": [],
Expand Down
12 changes: 6 additions & 6 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const path = require('path')
const test = require('tape')
const crossSpawn = require('cross-spawn')
import { fileURLToPath } from 'node:url'
import test from 'tape'
import crossSpawn from 'cross-spawn'

const CMD_PATH = path.join(__dirname, '..', 'bin', 'cmd.js')
const CMD_PATH = fileURLToPath(new URL('../bin/cmd.js', import.meta.url))

test('command line usage: --help', function (t) {
t.plan(2)
Expand All @@ -16,7 +16,7 @@ test('command line usage: --help', function (t) {
test('test-repo-eslintrc allows snake_case', function (t) {
t.plan(4)

const jsPath = path.join(__dirname, 'test-repo-eslintrc', 'index.js')
const jsPath = fileURLToPath(new URL('./test-repo-eslintrc/index.js', import.meta.url))
const result = crossSpawn.sync(CMD_PATH, [jsPath])

t.error(result.error)
Expand All @@ -29,7 +29,7 @@ test('test-repo-eslintrc allows snake_case', function (t) {
test('test-repo-package-json allows snake_case', function (t) {
t.plan(4)

const jsPath = path.join(__dirname, 'test-repo-package-json', 'index.js')
const jsPath = fileURLToPath(new URL('./test-repo-package-json/index.js', import.meta.url))
const result = crossSpawn.sync(CMD_PATH, [jsPath])

t.error(result.error)
Expand Down

0 comments on commit 2c02104

Please sign in to comment.