Skip to content

Commit 6d6c0c0

Browse files
refactor: use TypeScript and update to @babel 7 (#25)
1 parent bba6079 commit 6d6c0c0

File tree

15 files changed

+1674
-462
lines changed

15 files changed

+1674
-462
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Publish Canary
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [10.x, 12.x, 14.x]
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- run: yarn install --frozen-lockfile
23+
- run: yarn prettier:check
24+
- run: yarn test
25+
26+
publish-canary:
27+
runs-on: ubuntu-latest
28+
needs: test
29+
steps:
30+
- uses: actions/checkout@v2
31+
- uses: actions/setup-node@v1
32+
with:
33+
node-version: 12.x
34+
registry-url: 'https://registry.npmjs.org'
35+
- run: yarn install --frozen-lockfile
36+
- run: yarn build
37+
- run: npx rollingversions publish --canary $GITHUB_RUN_NUMBER
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Release
2+
on:
3+
repository_dispatch:
4+
types: [rollingversions_publish_approved]
5+
6+
jobs:
7+
test:
8+
runs-on: ubuntu-latest
9+
10+
strategy:
11+
matrix:
12+
node-version: [10.x, 12.x, 14.x]
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Use Node.js ${{ matrix.node-version }}
17+
uses: actions/setup-node@v1
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
- run: yarn install --frozen-lockfile
21+
- run: yarn prettier:check
22+
- run: yarn test
23+
24+
publish:
25+
runs-on: ubuntu-latest
26+
needs: test
27+
steps:
28+
- uses: actions/checkout@v2
29+
- uses: actions/setup-node@v1
30+
with:
31+
node-version: 12.x
32+
registry-url: 'https://registry.npmjs.org'
33+
- run: yarn install --frozen-lockfile
34+
- run: yarn build
35+
- run: npx rollingversions publish
36+
env:
37+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/test.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
matrix:
14+
node-version: [10.x, 12.x, 14.x]
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- run: yarn install --frozen-lockfile
23+
- run: yarn prettier:check
24+
- run: yarn test

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Compile time `with` for strict mode JavaScript
44

5-
[![build status](https://img.shields.io/travis/pugjs/with.svg)](http://travis-ci.org/pugjs/with)
6-
[![Dependency Status](https://img.shields.io/david/pugjs/with.svg)](https://david-dm.org/pugjs/with)
7-
[![NPM version](https://img.shields.io/npm/v/with.svg)](https://www.npmjs.com/package/with)
5+
[![Build Status](https://img.shields.io/github/workflow/status/pugjs/with/Publish%20Canary/master?style=for-the-badge)](https://github.com/pugjs/with/actions?query=workflow%3A%22Publish+Canary%22)
6+
[![Rolling Versions](https://img.shields.io/badge/Rolling%20Versions-Enabled-brightgreen?style=for-the-badge)](https://rollingversions.com/pugjs/with)
7+
[![NPM version](https://img.shields.io/npm/v/with?style=for-the-badge)](https://www.npmjs.com/package/with)
88

99
## Installation
1010

@@ -13,17 +13,17 @@ Compile time `with` for strict mode JavaScript
1313
## Usage
1414

1515
```js
16-
var addWith = require('with')
16+
var addWith = require('with');
1717

18-
addWith('obj', 'console.log(a)')
18+
addWith('obj', 'console.log(a)');
1919
// => ';(function (console, a) {
2020
// console.log(a)
2121
// }("console" in obj ? obj.console :
2222
// typeof console!=="undefined" ? console : undefined,
2323
// "a" in obj ? obj.a :
2424
// typeof a !== "undefined" ? a : undefined));'
2525

26-
addWith('obj', 'console.log(a)', ['console'])
26+
addWith('obj', 'console.log(a)', ['console']);
2727
// => ';(function (console, a) {
2828
// console.log(a)
2929
// }("a" in obj ? obj.a :
@@ -38,26 +38,26 @@ The idea is that this is roughly equivallent to:
3838

3939
```js
4040
with (obj) {
41-
src
41+
src;
4242
}
4343
```
4444

45-
There are a few differences though. For starters, assignments to variables will always remain contained within the with block.
45+
There are a few differences though. For starters, assignments to variables will always remain contained within the with block.
4646

4747
e.g.
4848

4949
```js
50-
var foo = 'foo'
50+
var foo = 'foo';
5151
with ({}) {
52-
foo = 'bar'
52+
foo = 'bar';
5353
}
54-
assert(foo === 'bar')// => This fails for compile time with but passes for native with
54+
assert(foo === 'bar'); // => This fails for compile time with but passes for native with
5555

56-
var obj = {foo: 'foo'}
56+
var obj = {foo: 'foo'};
5757
with ({}) {
58-
foo = 'bar'
58+
foo = 'bar';
5959
}
60-
assert(obj.foo === 'bar')// => This fails for compile time with but passes for native with
60+
assert(obj.foo === 'bar'); // => This fails for compile time with but passes for native with
6161
```
6262

6363
It also makes everything be declared, so you can always do:
@@ -72,16 +72,16 @@ instead of
7272
if (typeof foo === 'undefined')
7373
```
7474

75-
This is not the case if foo is in `exclude`. If a variable is excluded, we ignore it entirely. This is useful if you know a variable will be global as it can lead to efficiency improvements.
75+
This is not the case if foo is in `exclude`. If a variable is excluded, we ignore it entirely. This is useful if you know a variable will be global as it can lead to efficiency improvements.
7676

7777
It is also safe to use in strict mode (unlike `with`) and it minifies properly (`with` disables virtually all minification).
7878

7979
#### Parsing Errors
8080

81-
with internally uses babylon to parse code passed to `addWith`. If babylon throws an error, probably due to a syntax error, `addWith` returns an error wrapping the babylon error, so you can
82-
retrieve location information. `error.component` is `"src"` if the error is in the body or `"obj"` if it's in the object part of the with expression. `error.babylonError` is
81+
with internally uses babylon to parse code passed to `addWith`. If babylon throws an error, probably due to a syntax error, `addWith` returns an error wrapping the babylon error, so you can
82+
retrieve location information. `error.component` is `"src"` if the error is in the body or `"obj"` if it's in the object part of the with expression. `error.babylonError` is
8383
the error thrown from babylon.
8484

8585
## License
8686

87-
MIT
87+
MIT

package.json

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
"description": "Compile time `with` for strict mode JavaScript",
55
"main": "lib/index.js",
66
"scripts": {
7-
"prepublish": "babel -d lib src",
8-
"test": "babel-node node_modules/mocha/bin/_mocha test/index.js -R spec"
7+
"build": "tsc",
8+
"postbuild": "rimraf lib/**/__tests__",
9+
"lint": "tslint './src/**/*.{ts,tsx}' -t verbose -p .",
10+
"prettier:write": "prettier --ignore-path .gitignore --write './**/*.{md,json,yaml,js,jsx,ts,tsx}'",
11+
"prettier:check": "prettier --ignore-path .gitignore --list-different './**/*.{md,json,yaml,js,jsx,ts,tsx}'",
12+
"pretest": "yarn build",
13+
"test": "mocha test/index.js -R spec"
914
},
1015
"repository": {
1116
"type": "git",
@@ -14,17 +19,22 @@
1419
"author": "ForbesLindesay",
1520
"license": "MIT",
1621
"dependencies": {
17-
"babel-runtime": "^6.11.6",
18-
"babel-types": "^6.15.0",
19-
"babylon": "^6.9.1",
20-
"babylon-walk": "^1.0.2"
22+
"@babel/parser": "^7.9.6",
23+
"@babel/types": "^7.9.6",
24+
"assert-never": "^1.2.1",
25+
"babel-walk": "3.0.0-canary-5"
2126
},
2227
"devDependencies": {
23-
"babel-cli": "^6.14.0",
24-
"babel-plugin-add-module-exports": "^0.2.1",
25-
"babel-plugin-transform-runtime": "^6.15.0",
26-
"babel-preset-es2015": "^6.14.0",
28+
"@forbeslindesay/tsconfig": "^2.0.0",
29+
"@types/node": "^14.0.5",
2730
"mocha": "*",
31+
"prettier": "^2.0.5",
32+
"rimraf": "^3.0.2",
33+
"tslint": "^6.1.2",
34+
"typescript": "^3.9.3",
2835
"uglify-js": "^2.6.2"
36+
},
37+
"engines": {
38+
"node": ">= 10.0.0"
2939
}
30-
}
40+
}

prettier.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('@forbeslindesay/tsconfig/prettier');

src/globals.js

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)