Skip to content

Commit 2c02104

Browse files
jimmywartingvoxpelli
authored andcommitted
update to esm
1 parent 5cf1365 commit 2c02104

File tree

5 files changed

+36
-21
lines changed

5 files changed

+36
-21
lines changed

bin/cmd.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
#!/usr/bin/env node
2+
/* eslint-disable no-var, no-eval */
23

3-
if (process.version.match(/v(\d+)\./)[1] < 4) {
4-
console.error('standardx: Node v4 or greater is required. `standardx` did not run.')
4+
var match = process.version.match(/v(\d+)\.(\d+)/)
5+
var major = parseInt(match[1], 10)
6+
var minor = parseInt(match[2], 10)
7+
8+
if (major >= 12 || (major === 12 && minor >= 20)) {
9+
eval('import("standard-engine")').then(function (standardEngine) {
10+
eval('import("../options.js")').then(function (options) {
11+
standardEngine.cli(options.default)
12+
})
13+
})
514
} else {
6-
const opts = require('../options')
7-
require('standard-engine').cli(opts)
15+
console.error('standardx: Node 12.20.0 or greater is required. `standardx` did not run.')
816
}

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*! standardx. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
2-
const Linter = require('standard-engine').linter
3-
const opts = require('./options')
2+
import standardEngine from 'standard-engine'
3+
import opts from './options.js'
44

5-
module.exports = new Linter(opts)
5+
const Linter = standardEngine.linter
6+
7+
export default new Linter(opts)

options.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
const pkg = require('./package.json')
2-
const stdVersion = require('standard/package.json').version
3-
const stdOpts = require('standard/options.js')
1+
import { readFileSync } from 'node:fs'
2+
import stdOpts from 'standard/options.js'
43

5-
const opts = Object.assign({}, stdOpts, {
4+
const stdVersion = stdOpts.version
5+
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'))
6+
const baseConfig = JSON.parse(readFileSync(stdOpts.eslintConfig.configFile, 'utf-8'))
7+
8+
export default Object.assign({}, stdOpts, {
69
bugs: pkg.bugs.url,
710
cmd: 'standardx',
811
eslintConfig: {
9-
baseConfig: require('standard/eslintrc.json'),
12+
baseConfig,
1013
useEslintrc: true
1114
},
1215
homepage: pkg.homepage,
1316
tagline: 'Use JavaScript Standard Style (tweaked by standardx)',
1417
version: `${pkg.version} (standard ${stdVersion})`
1518
})
16-
17-
module.exports = opts

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@
1111
"bugs": {
1212
"url": "https://github.com/standard/standardx/issues"
1313
},
14+
"type": "module",
1415
"dependencies": {
1516
"standard": "^16.0.1",
1617
"standard-engine": "^14.0.1"
1718
},
1819
"devDependencies": {
1920
"cross-spawn": "^7.0.3",
2021
"tap-spec": "^5.0.0",
21-
"tape": "^5.0.1"
22+
"tape": "^5.3.1"
23+
},
24+
"engines": {
25+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
2226
},
2327
"homepage": "https://github.com/standard/standardx",
2428
"keywords": [],

test/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const path = require('path')
2-
const test = require('tape')
3-
const crossSpawn = require('cross-spawn')
1+
import { fileURLToPath } from 'node:url'
2+
import test from 'tape'
3+
import crossSpawn from 'cross-spawn'
44

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

77
test('command line usage: --help', function (t) {
88
t.plan(2)
@@ -16,7 +16,7 @@ test('command line usage: --help', function (t) {
1616
test('test-repo-eslintrc allows snake_case', function (t) {
1717
t.plan(4)
1818

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

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

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

3535
t.error(result.error)

0 commit comments

Comments
 (0)