Skip to content

Commit

Permalink
feat: emit esm build
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Mar 6, 2022
1 parent ea0ab5c commit 168fb8f
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ typings/
.next

# app
dist
dist-*
.vscode
.swc

Expand Down
25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,27 @@
"name": "dripip",
"version": "0.0.0-dripip",
"description": "Opinionated CLI for continuous delivery of npm packages",
"main": "dist/cli/main",
"bin": "dist/cli/main.js",
"main": "dist-cjs/cli/main",
"bin": "dist-cjs/cli/main.js",
"repository": "git@github.com:prisma-labs/dripip.git",
"packageManager": "yarn@3.2.0",
"author": "Jason Kuhrt <jasonkuhrt@me.com>",
"license": "MIT",
"files": [
"/src",
"/dist"
"src",
"dist-cjs",
"dist-esm"
],
"scripts": {
"release:stable": "yarn dripip stable",
"release:preview": "yarn dripip preview",
"release:pr": "yarn dripip pr",
"format": "prettier --write .",
"dripip": "ts-node src/cli/main",
"clean": "rm -rf dist",
"build": "tsc",
"build": "yarn clean && yarn build:cjs && yarn build:esm",
"build:cjs": "tsc --project tsconfig.cjs.json",
"build:esm": "tsc --project tsconfig.esm.json",
"clean": "rm -rf dist-cjs dist-esm node_modules/.cache",
"dev": "tsc --watch",
"type-check": "yarn tsc --noEmit",
"dev:test": "jest --watch --testPathPattern '.*/src/.*'",
Expand All @@ -28,8 +31,7 @@
"test": "jest --testTimeout 15000 --verbose",
"build:docs:toc": "doctoc README.md",
"build:docs": "yarn build:docs:commands && yarn build:docs:toc",
"postpublish": "yarn run clean",
"prepublishOnly": "yarn run build"
"prepack": "yarn build"
},
"dependencies": {
"@octokit/rest": "^18.12.0",
Expand All @@ -47,13 +49,15 @@
"parse-github-url": "^1.0.2",
"request": "^2.88.2",
"simple-git": "^2.23.0",
"tslib": "^2.3.1",
"yargs": "^17.3.1"
},
"devDependencies": {
"@prisma-labs/prettier-config": "0.1.0",
"@swc/core": "^1.2.148",
"@swc/helpers": "^0.3.6",
"@swc/jest": "^0.2.20",
"@tsconfig/node14": "^1.0.1",
"@types/common-tags": "1.8.1",
"@types/jest": "27.4.1",
"@types/node": "17.0.21",
Expand All @@ -69,8 +73,11 @@
"tmp": "0.2.1",
"ts-jest": "27.1.3",
"ts-node": "10.6.0",
"tsconfig-paths": "^3.13.0",
"type-fest": "2.12.0",
"typescript": "4.6.2"
"typescript": "4.6.2",
"typescript-snapshots-plugin": "^1.7.0",
"typescript-transform-paths": "^3.3.1"
},
"prettier": "@prisma-labs/prettier-config"
}
8 changes: 4 additions & 4 deletions src/lib/conventional-commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ export function parse(message: string): null | ConventionalCommit {
footers = rawFooters.map((f) => {
const [, type, body] = f.trim().split(/^\s*([\w-]+)\s*:/)
return {
type: type.trim(),
body: body.trim(),
type: type!.trim(),
body: body!.trim(),
}
})
}

const typeTrimmed = type.trim()
const typeTrimmed = type!.trim()

return {
typeKind: getKind(typeTrimmed),
type: typeTrimmed,
scope: scope?.trim() ?? null,
description: description.trim(),
description: description!.trim(),
body: body?.trim() ?? null,
footers: footers ?? [],
breakingChange: breakingChange?.trim() ?? null,
Expand Down
6 changes: 3 additions & 3 deletions src/lib/github-ci-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export function parseGitHubCIEnvironment(): null | GitHubCIEnvironment {

if (match) {
debug('found a pr number from github ci environment %s', match[1])
prNum = parseInt(match[1], 10)
prNum = parseInt(match[1]!, 10)
}
}

const repoPath = process.env.GITHUB_REPOSITORY!.split('/')

const repo = {
owner: repoPath[0],
name: repoPath[1],
owner: repoPath[0]!,
name: repoPath[1]!,
}

let branchName: null | string = null
Expand Down
4 changes: 2 additions & 2 deletions src/lib/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function parseCommandString(cmd: string): { name: string; args: string[] } {
const [name, ...args] = cmd.split(' ')

return {
name,
name: name!,
args,
}
}
Expand All @@ -210,7 +210,7 @@ function isFailedExitCode(exitCode: null | number): boolean {
* @param packageJsonPath
*/
export function isProcessFromProjectBin(packageJsonPath: string): boolean {
const processBinPath = process.argv[1]
const processBinPath = process.argv[1]!
const processBinDirPath = Path.dirname(processBinPath)
const projectBinDirPath = Path.join(Path.dirname(packageJsonPath), 'node_modules/.bin')
return processBinDirPath !== projectBinDirPath
Expand Down
16 changes: 8 additions & 8 deletions src/lib/semver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ export function parse(ver: string): null | StableVer | PreviewVer {

if (result[6]) {
const vprefix = result[5] === 'v'
const major = parseInt(result[6], 10)
const minor = parseInt(result[7], 10)
const patch = parseInt(result[8], 10)
const identifier = result[9]
const buildNum = parseInt(result[10], 10)
const major = parseInt(result[6]!, 10)
const minor = parseInt(result[7]!, 10)
const patch = parseInt(result[8]!, 10)
const identifier = result[9]!
const buildNum = parseInt(result[10]!, 10)
return {
version: `${major}.${minor}.${patch}-${identifier}.${buildNum}`,
vprefix,
Expand All @@ -162,9 +162,9 @@ export function parse(ver: string): null | StableVer | PreviewVer {
}

const vprefix = result[1] === 'v'
const major = parseInt(result[2], 10)
const minor = parseInt(result[3], 10)
const patch = parseInt(result[4], 10)
const major = parseInt(result[2]!, 10)
const minor = parseInt(result[3]!, 10)
const patch = parseInt(result[4]!, 10)
return {
version: `${major}.${minor}.${patch}`,
vprefix,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function delay(milliseconds: number): Promise<void> {
*/
export function findIndexFromEnd<T>(xs: T[], f: (x: T) => boolean): number {
for (let index = xs.length - 1; index > -1; index--) {
if (f(xs[index])) return index
if (f(xs[index]!)) return index
}
return -1
}
Expand All @@ -122,7 +122,7 @@ export function findIndexFromEnd<T>(xs: T[], f: (x: T) => boolean): number {
*/
export function last<T>(xs: T[]): null | T {
if (xs.length === 0) return null
return xs[xs.length - 1]
return xs[xs.length - 1]!
}

export function numericAscending(n1: number, n2: number): -1 | 0 | 1 {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export async function getLocationContext({
maybePR = (await octokit.pulls.list({ owner, repo, head, state })).data[0]
} catch (e) {
throw new Error(
`Failed to fetch ${state} pull requests from ${owner}/${name} for head ${head} in order to find out if this branch has an open pull-request.\n\n${e}`
`Failed to fetch ${state} pull requests from ${owner}/${repo} for head ${head} in order to find out if this branch has an open pull-request.\n\n${e}`
)
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/pr-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function getNextPreReleaseBuildNumFromVersions(prefix: string, versions: string[
if (match[1] !== undefined) return match[1]
if (match[2] !== undefined) return match[2]
// never
return null
})
.filter((v) => v !== null)
.map((v) => Number(v))
Expand Down
13 changes: 13 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist-cjs",
"module": "commonjs",
"rootDir": "src",
"sourceMap": true,
"declaration": true,
"declarationMap": true
},
"include": ["src"],
"exclude": ["src/**/*.spec.ts"]
}
14 changes: 14 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "dist-esm",
"module": "ES2015",
"moduleResolution": "node",
"rootDir": "src",
"sourceMap": true,
"declaration": true,
"declarationMap": true
},
"include": ["src"],
"exclude": ["src/**/*.spec.ts"]
}
54 changes: 44 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,48 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"ts-node": {
"swc": true,
"require": ["tsconfig-paths/register"],
"compilerOptions": {
// Sometimes projects (e.g. Nextjs) will want code to emit ESM but ts-node will not work with that.
"module": "CommonJS"
}
},
"compilerOptions": {
"rootDir": "src",
"outDir": "dist",
"module": "commonjs",
"target": "es2016",
"strict": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true
// Make the compiler stricter, catch more errors
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
// We handle these with ESLint:
// "noUnusedLocals": false,
// "noUnusedParameters": false,

// Output
"importHelpers": true,

// DX
"incremental": true,
"tsBuildInfoFile": "node_modules/.cache/.tsbuildinfo",
"noErrorTruncation": true,
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
},

// Transformer Plugins made possible by https://github.com/nonara/ts-patch
"plugins": [
// https://github.com/LeDDGroup/typescript-transform-paths
{ "transform": "typescript-transform-paths" },
{ "transform": "typescript-transform-paths", "afterDeclarations": true }
]
},
"include": ["src"],
"exclude": ["src/**/*.spec.ts"]
"include": ["src", "tests", "scripts", "jest.*"],
// Prevent unwanted things like auto-import from built modules
"exclude": ["dist-*"],
"plugins": [
{
"name": "typescript-snapshots-plugin"
}
]
}
Loading

0 comments on commit 168fb8f

Please sign in to comment.