Skip to content

Commit

Permalink
feat: add TypeScript v4.7 support. Add NODE_ESM preset. Add support f…
Browse files Browse the repository at this point in the history
…or evaluating new.target and import.meta meta properties
  • Loading branch information
wessberg committed Jun 7, 2022
1 parent 476d626 commit dbe0433
Show file tree
Hide file tree
Showing 252 changed files with 1,944 additions and 1,427 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ jobs:

strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-18.04]
node: [14, 16, 17]
os: [windows-latest, macos-latest, ubuntu-latest]
node: [14.19.0, 16, 17, 18]

steps:
- name: Checkout code
Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<a href="https://npmcharts.com/compare/ts-evaluator?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/ts-evaluator.svg" /></a>
<a href="https://www.npmjs.com/package/ts-evaluator"><img alt="NPM version" src="https://badge.fury.io/js/ts-evaluator.svg" /></a>
<a href="https://david-dm.org/wessberg/ts-evaluator"><img alt="Dependencies" src="https://img.shields.io/david/wessberg%2Fts-evaluator.svg" /></a>
<img alt="Dependencies" src="https://img.shields.io/librariesio/github/wessberg%2Fts-evaluator.svg" />
<a href="https://github.com/wessberg/ts-evaluator/graphs/contributors"><img alt="Contributors" src="https://img.shields.io/github/contributors/wessberg%2Fts-evaluator.svg" /></a>
<a href="https://github.com/prettier/prettier"><img alt="code style: prettier" src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" /></a>
<a href="https://opensource.org/licenses/MIT"><img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" /></a>
Expand Down Expand Up @@ -64,9 +64,9 @@ If you are looking for a Typescript REPL, or a way to _execute_ a full Typescrip

[Become a sponsor/backer](https://github.com/wessberg/ts-evaluator?sponsor=1) and get your logo listed here.

| <a href="https://usebubbles.com"><img alt="Bubbles" src="https://uploads-ssl.webflow.com/5d682047c28b217055606673/5e5360be16879c1d0dca6514_icon-thin-128x128%402x.png" height="70" /></a> | <a href="https://github.com/cblanc"><img alt="Christopher Blanchard" src="https://avatars0.githubusercontent.com/u/2160685?s=400&v=4" height="70" /></a> | <a href="https://github.com/ideal-postcodes"><img alt="Ideal Postcodes" src="https://avatars.githubusercontent.com/u/4996310?s=200&v=4" height="70" /></a> | <a href="https://www.xerox.com"><img alt="Xerox" src="https://avatars.githubusercontent.com/u/9158512?s=200&v=4" height="70" /></a> | <a href="https://changelog.me"><img alt="Trent Raymond" src="https://avatars.githubusercontent.com/u/1509616?v=4" height="70" /></a> | <a href="https://scrubtheweb.com"><img alt="scrubtheweb" src="https://avatars.githubusercontent.com/u/41668218?v=4" height="70" /></a> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| [Bubbles](https://usebubbles.com)<br><strong>Twitter</strong>: [@usebubbles](https://twitter.com/usebubbles) | [Christopher Blanchard](https://github.com/cblanc) | [Ideal Postcodes](https://github.com/ideal-postcodes) | [Xerox](https://www.xerox.com) | [Trent Raymond](https://changelog.me) | [scrubtheweb](https://scrubtheweb.com) |
| <a href="https://usebubbles.com"><img alt="Bubbles" src="https://uploads-ssl.webflow.com/5d682047c28b217055606673/5e5360be16879c1d0dca6514_icon-thin-128x128%402x.png" height="70" /></a> | <a href="https://github.com/cblanc"><img alt="Christopher Blanchard" src="https://avatars0.githubusercontent.com/u/2160685?s=400&v=4" height="70" /></a> | <a href="https://github.com/ideal-postcodes"><img alt="Ideal Postcodes" src="https://avatars.githubusercontent.com/u/4996310?s=200&v=4" height="70" /></a> | <a href="https://www.xerox.com"><img alt="Xerox" src="https://avatars.githubusercontent.com/u/9158512?s=200&v=4" height="70" /></a> | <a href="https://changelog.me"><img alt="Trent Raymond" src="https://avatars.githubusercontent.com/u/1509616?v=4" height="70" /></a> | <a href="https://scrubtheweb.com"><img alt="scrubtheweb" src="https://avatars.githubusercontent.com/u/41668218?v=4" height="70" /></a> | <a href="https://github.com/hjoelh"><img alt="Joel" src="https://avatars.githubusercontent.com/u/68335961?v=4" height="70" /></a> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| [Bubbles](https://usebubbles.com)<br><strong>Twitter</strong>: [@usebubbles](https://twitter.com/usebubbles) | [Christopher Blanchard](https://github.com/cblanc) | [Ideal Postcodes](https://github.com/ideal-postcodes) | [Xerox](https://www.xerox.com) | [Trent Raymond](https://changelog.me) | [scrubtheweb](https://scrubtheweb.com) | [Joel](https://github.com/hjoelh) |

### Patreon

Expand Down Expand Up @@ -128,7 +128,7 @@ $ pnpm add ts-evaluator

`ts-evaluator` depends on `typescript`, so you need to manually install this as well.

You may also need to install additional peer dependencies such as `jsdom` or `chalk` depending on the features you are going to use. Refer to the documentation for the specific cases where any of these may be relevant.
You may also need to install `jsdom` depending on the features you are going to use. Refer to the documentation for the specific cases where it may be relevant.

<!-- SHADOW_SECTION_INSTALL_END -->

Expand Down Expand Up @@ -164,12 +164,14 @@ you don't have to evaluate the entire program to produce a value which may poten

### Setting up an environment

You can define the kind of environment that `evaluate()` assumes when evaluating the given Node. By default, a `Node` environment is assumed.
You can define the kind of environment that `evaluate()` assumes when evaluating the given Node. By default, a CommonJS-based `Node` environment is assumed, to align with what you would get simply by running `node` with no arguments.

The following environment presets are supported:

- `ECMA` - Assumes a pure ECMAScript environment. This means that no other globals than those that are defined in the ECMAScript spec such as `Math`, `Promise`, `Object`, etc, are available.
- `NODE` _(default)_ - Assumes a Node environment. This means that built-in modules such as `fs` and `path` can be resolved, and Node-specific globals such as `process` is present.
- `NODE` _(default)_ - Assumes a CommonJS-based Node.js environment. This means that built-in modules such as `fs` and `path` can be resolved, and Node-specific globals such as `process` is present, as well as ones that are only present in a CommonJS-based Node.js environment, such as `require`, `__dirname`, and `__filename`.
- `NODE_CJS` - An alias for `NODE`.
- `NODE_ESM` - Assumes an ESM-based Node.js environment. This means that built-in modules such as `fs` and `path` can be resolved, and Node-specific globals such as `process` is present, as well as ones that are only present in an ESM-based Node.js environment, such as `import.meta`.
- `BROWSER` - Assumes a Browser environment. This means that DOM APIs are available and Browser-specific globals such as `window` is present.

Beyond presets, you can provide additional globals or override those that comes from the presets.
Expand All @@ -179,7 +181,7 @@ Here's how you can configure environment options:
const result = evaluate({
// ...
environment: {
// The "Node" environment is the default one. You can simply omit this key if you are targeting a Node environment
// The "Node" environment is the default one. You can simply omit this key if you are targeting a CommonJS-based Node environment
preset: "NODE",
extra: {
someGlobal: "someValue"
Expand Down
69 changes: 36 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"preversion": "pnpm run lint && pnpm run build",
"version": "pnpm run generate:all && git add .",
"release": "np --no-cleanup --no-yarn --no-tests",
"update:check": "pnpx npm-check-updates -x typescript-*,chalk,ava --dep dev,prod",
"update:commit": "pnpx npm-check-updates -u -x typescript-*,chalk,ava --dep dev,prod && pnpm update && pnpm install"
"update:check": "pnpx npm-check-updates -x typescript-*,ava --dep dev,prod",
"update:commit": "pnpx npm-check-updates -u -x typescript-*,ava --dep dev,prod && pnpm update && pnpm install"
},
"keywords": [
"typescript",
Expand All @@ -45,36 +45,36 @@
"license": "MIT",
"devDependencies": {
"@types/jsdom": "^16.2.14",
"@types/node": "^17.0.35",
"@types/node": "^17.0.37",
"@types/object-path": "^0.11.1",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.26.0",
"@typescript-eslint/parser": "^5.26.0",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"@wessberg/ts-config": "^2.0.2",
"rollup-plugin-ts": "2.0.7",
"@wessberg/prettier-config": "^1.0.0",
"rollup-plugin-ts": "3.0.1",
"ava": "^3.15.0",
"crosspath": "^1.0.0",
"crosspath": "^2.0.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.3.1",
"eslint-plugin-jsdoc": "^39.3.2",
"helpertypes": "^0.0.18",
"husky": "^8.0.1",
"memfs": "^3.4.3",
"memfs": "^3.4.4",
"np": "7.6.1",
"npm-check-updates": "^13.0.3",
"pnpm": "^7.1.5",
"pnpm": "^7.1.7",
"prettier": "^2.6.2",
"pretty-quick": "^3.1.3",
"rimraf": "^3.0.2",
"rollup": "^2.74.1",
"sandhog": "^1.0.43",
"rollup": "^2.75.4",
"sandhog": "^2.0.2",
"semver": "7.3.7",
"jsdom": "^19.0.0",
"chalk": "^4.1.2",
"standard-changelog": "^2.0.27",
"ts-node": "^10.8.0",
"typescript": "4.6.4",
"typescript": "^4.7.2",
"typescript-3-4-1": "npm:typescript@3.4.1",
"typescript-3-5-1": "npm:typescript@3.5.1",
"typescript-3-6-2": "npm:typescript@3.6.2",
Expand All @@ -90,27 +90,26 @@
"typescript-4-6-4": "npm:typescript@4.6.4"
},
"dependencies": {
"ansi-colors": "^4.1.3",
"object-path": "^0.11.8"
},
"peerDependencies": {
"typescript": ">=3.2.x || >= 4.x",
"jsdom": ">=14.x",
"chalk": ">=4.x"
"jsdom": ">=14.x"
},
"peerDependenciesMeta": {
"jsdom": {
"optional": true
},
"chalk": {
"optional": true
}
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"browser": "./dist/esm/index.js",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.cjs"
},
"type": "module",
"types": "./dist/esm/index.d.ts",
"typings": "./dist/esm/index.d.ts",
"es2015": "./dist/esm/index.js",
"main": "./dist/cjs/index.cjs",
"module": "./dist/esm/index.js",
"funding": {
"type": "github",
"url": "https://github.com/wessberg/ts-evaluator?sponsor=1"
Expand All @@ -123,22 +122,26 @@
"url": "https://github.com/wessberg/ts-evaluator/issues"
},
"engines": {
"node": ">=10.1.0"
"node": ">=14.19.0"
},
"prettier": "@wessberg/prettier-config",
"ava": {
"files": [
"test/**/**.test.ts"
],
"verbose": true,
"timeout": "300s",
"extensions": [
"ts"
"timeout": "400s",
"nonSemVerExperiments": {
"configurableModuleFormat": true
},
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=ts-node/esm"
],
"environmentVariables": {
"NODE_OPTIONS": "--max_old_space_size=4096"
},
"require": [
"ts-node/register/transpile-only"
]
"FORCE_COLOR": "3"
}
}
}
Loading

0 comments on commit dbe0433

Please sign in to comment.