Skip to content

Commit cd0a493

Browse files
committed
Fix ESM module
1 parent 8a40d77 commit cd0a493

File tree

7 files changed

+82
-10
lines changed

7 files changed

+82
-10
lines changed

.github/workflows/publish.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ name: Publish to NPM
22
on:
33
release:
44
types: [ created ]
5+
56
jobs:
67
build:
78
runs-on: ubuntu-latest
89
steps:
910
- uses: actions/checkout@v2
10-
# Setup .npmrc file to publish to npm
11-
- uses: actions/setup-node@v2
11+
- uses: actions/setup-node@v3
1212
with:
13-
node-version: '12.x'
13+
node-version: 14
1414
registry-url: 'https://registry.npmjs.org'
15-
- run: npm install
16-
- run: npm publish
15+
16+
- name: Install dependencies
17+
run: npm ci
18+
19+
- name: Inject version
20+
run: echo "PACKAGE_VERSION=$(git describe --tags)" >> $GITHUB_ENV
21+
22+
- name: Publish to NPM
23+
run: npm run release:prod
1724
env:
18-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
25+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

bin/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

bin/postpublish.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { removeSync, pathExistsSync, moveSync } = require('fs-extra')
2+
3+
if (pathExistsSync('./package.json')) {
4+
removeSync('./package.json')
5+
}
6+
7+
if (pathExistsSync('./package.backup.json')) {
8+
moveSync('./package.backup.json', './package.json')
9+
}

bin/prepublish.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
const { writeFileSync, copySync, pathExistsSync } = require('fs-extra')
2+
const yargs = require('yargs/yargs')
3+
const { hideBin } = require('yargs/helpers')
4+
const argv = yargs(hideBin(process.argv)).argv
5+
6+
let pkg = require('../package.json')
7+
8+
const development = argv.dev
9+
const production = argv.prod
10+
11+
if (!development && !production) {
12+
throw new Error('Unknown environment.')
13+
}
14+
15+
let version = '0.1.' + ~~(Date.now() / 1000)
16+
let name = '@aaron-dev/remark-torchlight'
17+
18+
if (production) {
19+
// Populated by GitHub actions
20+
version = process.env.PACKAGE_VERSION
21+
name = 'remark-torchlight'
22+
}
23+
24+
if (pathExistsSync('./package.backup.json')) {
25+
throw new Error('package.backup.json already exists, not overwriting.')
26+
}
27+
28+
copySync('./package.json', './package.backup.json')
29+
30+
pkg = {
31+
...pkg,
32+
name,
33+
version: version
34+
}
35+
36+
writeFileSync('./package.json', JSON.stringify(pkg, null, 2))

bin/release

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ "$1" != "dev" ] && [ "$1" != "prod" ]; then
6+
echo "The first argument must be 'dev' or 'prod'."
7+
exit
8+
fi
9+
10+
set -x
11+
12+
node ./bin/prepublish.js --"$1"
13+
npm publish --access public
14+
node ./bin/postpublish.js --"$1"

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
{
22
"name": "remark-torchlight",
3-
"version": "0.0.2",
3+
"version": "0.0.3",
44
"description": "A remark plugin for Torchlight - the syntax highlighting API.",
55
"main": "index.js",
6+
"type": "module",
67
"scripts": {
7-
"test": "standard --env jest && jest"
8+
"test": "standard --env jest && jest",
9+
"release:dev": "./bin/release dev",
10+
"release:prod": "./bin/release prod"
811
},
912
"keywords": [
1013
"syntax",
@@ -26,7 +29,7 @@
2629
"author": "Aaron Francis <aaron@hammerstone.dev> (https://torchlight.dev)",
2730
"license": "MIT",
2831
"dependencies": {
29-
"@torchlight-api/torchlight-cli": "^0.1.2",
32+
"@torchlight-api/torchlight-cli": "^0.1.7",
3033
"hast-util-from-parse5": "^7.1.0",
3134
"parse5": "^6.0.1",
3235
"unist-util-map": "^3.0.0"

tests/render.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import torchlight from '../index'
1+
import torchlight from '../index.js'
22
import { remark } from 'remark'
33
import html from 'remark-html'
44
import {mockApi} from '@torchlight-api/torchlight-cli/tests/support/helpers'

0 commit comments

Comments
 (0)