Skip to content

Commit

Permalink
[ENG-4579][scripts] convert to ESM (#1192)
Browse files Browse the repository at this point in the history
* upgrade typescript to 4.7.4

* [scripts] add extensions to imports

* [scripts] configure as ESM

* [scripts] fix after converting to ESM

* [scripts] fix lint

* [scripts] require node >= 14.16

* [scripts] add node: protocol

* add scripts/build to .gitignore

* [scripts] add typecheck script

* add workflow for testing scripts

* address PR feedback
  • Loading branch information
dsokal authored Jul 4, 2022
1 parent 8bce9b1 commit 04a8b08
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 45 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test-scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test scripts

defaults:
run:
working-directory: scripts

on:
push:
branches: [main]
paths:
- 'scripts/**'
pull_request:
paths:
- 'scripts/**'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: 18
- run: yarn install --frozen-lockfile --check-files
- run: yarn typecheck
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
packages/*/build
packages/eas-cli/dist
packages/eas-cli/tmp
scripts/build

# Code editors
.idea
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"oclif": "3.0.1",
"prettier": "2.6.2",
"ts-jest": "28.0.2",
"typescript": "4.6.4"
"typescript": "4.7.4"
},
"volta": {
"node": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"nock": "13.2.4",
"tempy": "0.7.0",
"ts-deepmerge": "2.0.1",
"typescript": "4.6.4"
"typescript": "4.7.4"
},
"engines": {
"node": ">=14.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/eas-json/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"devDependencies": {
"@types/fs-extra": "9.0.13",
"memfs": "3.4.3",
"typescript": "4.6.4"
"typescript": "4.7.4"
},
"engines": {
"node": ">=14.0.0"
Expand Down
File renamed without changes.
17 changes: 9 additions & 8 deletions scripts/package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
{
"name": "scripts",
"private": true,
"type": "module",
"version": "0.31.0",
"scripts": {
"changelog-entry": "ts-node src/changelogEntry.ts",
"release-changelog": "ts-node src/releaseChangelog.ts",
"update-local-plugin": "./src/updateLocalPlugin.sh"
"changelog-entry": "ts-node-esm src/changelogEntry.ts",
"release-changelog": "ts-node-esm src/releaseChangelog.ts",
"update-local-plugin": "./src/updateLocalPlugin.sh",
"typecheck": "tsc"
},
"author": "Expo <[email protected]>",
"license": "MIT",
"engines": {
"node": ">=14.0.0"
"node": ">=14.16"
},
"dependencies": {
"dateformat": "4.5.1",
"fs-extra": "10.1.0",
"lodash": "4.17.21",
"lodash-es": "4.17.21",
"marked": "3.0.4",
"nullthrows": "1.1.1",
"semver": "7.3.7",
"tslib": "2.4.0"
},
"devDependencies": {
"@types/dateformat": "3.0.1",
"@types/fs-extra": "9.0.13",
"@types/lodash": "4.14.182",
"@types/lodash-es": "4.17.6",
"@types/node": "17.0.32",
"@types/semver": "7.3.9",
"ts-node": "10.7.0",
"typescript": "4.6.4"
"typescript": "4.7.4"
}
}
4 changes: 2 additions & 2 deletions scripts/src/changelog/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import { URL } from 'node:url';

export enum EntryCategory {
BreakingChange = 'breaking-change',
Expand All @@ -7,7 +7,7 @@ export enum EntryCategory {
Chore = 'chore',
}

export const CHANGELOG_PATH = path.join(__dirname, '../../../CHANGELOG.md');
export const CHANGELOG_PATH = new URL('../../../CHANGELOG.md', import.meta.url);

export const CATEGORY_HEADERS: Record<EntryCategory, string> = {
[EntryCategory.BreakingChange]: '🛠 Breaking changes',
Expand Down
4 changes: 2 additions & 2 deletions scripts/src/changelog/file.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra';

import * as markdown from '../markdown';
import { CHANGELOG_PATH } from './consts';
import * as markdown from '../markdown.js';
import { CHANGELOG_PATH } from './consts.js';

export async function readAndParseChangelogAsync(): Promise<markdown.Tokens> {
const contents = await fs.readFile(CHANGELOG_PATH, 'utf8');
Expand Down
9 changes: 4 additions & 5 deletions scripts/src/changelogEntry.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import nullthrows from 'nullthrows';

import { CATEGORY_HEADERS, EntryCategory } from './changelog/consts';
import { readAndParseChangelogAsync, writeChangelogAsync } from './changelog/file';
import * as markdown from './markdown';
import { CATEGORY_HEADERS, EntryCategory } from './changelog/consts.js';
import { readAndParseChangelogAsync, writeChangelogAsync } from './changelog/file.js';
import * as markdown from './markdown.js';
import { nullthrows } from './nullthrows.js';

const [rawCategory, ...rest] = process.argv.slice(2);
const message = rest.join(' ');
Expand Down
2 changes: 1 addition & 1 deletion scripts/src/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// this is mostly copy-pasted from https://github.com/expo/expo/blob/master/tools/src/Markdown.ts

import { unescape } from 'lodash';
import { unescape } from 'lodash-es';
import marked from 'marked';

export enum TokenType {
Expand Down
9 changes: 9 additions & 0 deletions scripts/src/nullthrows.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function nullthrows<T>(value: T | null | undefined, message?: string): T {
if (value !== null && value !== undefined) {
return value;
}

const error = new Error(message !== undefined ? message : `Got unexpected ${value}`);
(error as any).framesToPop = 1; // Skip nullthrows's own stack frame.
throw error;
}
6 changes: 3 additions & 3 deletions scripts/src/releaseChangelog.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import dateFormat from 'dateformat';
import semver from 'semver';

import { CATEGORY_HEADERS } from './changelog/consts';
import { readAndParseChangelogAsync, writeChangelogAsync } from './changelog/file';
import * as markdown from './markdown';
import { CATEGORY_HEADERS } from './changelog/consts.js';
import { readAndParseChangelogAsync, writeChangelogAsync } from './changelog/file.js';
import * as markdown from './markdown.js';

const MAIN_CATEGORIES = Object.values(CATEGORY_HEADERS).map(text =>
markdown.createHeadingToken(text, 3)
Expand Down
7 changes: 3 additions & 4 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"importHelpers": true,
"module": "commonjs",
"esModuleInterop": true,
"module": "node16",
"moduleResolution": "node16",
"noImplicitReturns": true,
"strict": true,
"target": "ES2019",
"target": "ES2020",
"outDir": "build",
"rootDir": "src",
"typeRoots": [
Expand Down
28 changes: 15 additions & 13 deletions scripts/yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04a8b08

Please sign in to comment.