Skip to content

Commit

Permalink
fix: working ESM build (DX-903) (#492)
Browse files Browse the repository at this point in the history
<!-- You can erase any parts of this template not applicable to your Pull Request. -->

**Fixes or implements DX-903**

### Brief description. What is this change?

Use standard tsconfig strategy from other typescript monorepos
Remove old packages which have been moved to `platform`

### Checklist

- [ ] Breaking changes have been communicated, including:
    - New required environment variables
    - Renaming of interfaces (API routes, request/response interface, etc)
- [ ] New environment variables have [been deployed](https://www.notion.so/voiceflow/Add-Environment-Variables-be1b0136479f45f1adece7995a7adbfb)
- [ ] Appropriate tests have been written
    - Bug fixes are accompanied by an updated or new test
    - New features are accompanied by a new test

Co-authored-by: Ben Teichman <[email protected]>
  • Loading branch information
effervescentia and effervescentia committed Jan 5, 2024
1 parent b45c2b9 commit ab7c8b4
Show file tree
Hide file tree
Showing 233 changed files with 5,183 additions and 4,723 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"packages": ["packages/*"],
"packages": ["packages/*", "meta/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "independent",
Expand Down
5 changes: 5 additions & 0 deletions meta/jest-config/global-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = () => {
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
process.env.NODE_ENV = 'test';
}
};
23 changes: 23 additions & 0 deletions meta/jest-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const path = require('path');
const swcConfig = require('@voiceflow-meta/swc-config/base.json');

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
transform: {
'^.+\\.(t|j)s?$': ['@swc/jest', Object.assign(swcConfig, { sourceMaps: 'inline' })],
},
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
modulePathIgnorePatterns: ['<rootDir>/build/'],
testMatch: ['<rootDir>/src/**/*.test.ts'],
testEnvironment: 'node',
collectCoverage: false,
coverageProvider: 'v8',
coverageReporters: ['clover', 'json', 'lcov'],
collectCoverageFrom: ['<rootDir>/src/**/*.{ts,js}', '!**/node_modules/**'],
coverageDirectory: '<rootDir>/sonar/coverage',
globalSetup: path.join(__dirname, 'global-setup.js'),
maxWorkers: process.env.CI ? 4 : '50%',
};
15 changes: 15 additions & 0 deletions meta/jest-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "@voiceflow-meta/jest-config",
"version": "1.0.0",
"private": true,
"main": "index.js",
"files": [
"index.js"
],
"dependencies": {
"@swc/core": "1.3.21",
"@swc/jest": "0.2.23",
"@types/jest": "^29.2.3",
"@voiceflow-meta/swc-config": "workspace:*"
}
}
23 changes: 23 additions & 0 deletions meta/swc-config/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"target": "es2021",
"parser": {
"syntax": "typescript",
"decorators": true
},
"baseUrl": "./",
"paths": {
"@/*": ["./src/*"]
}
},
"module": {
"type": "commonjs"
},
"env": {
"targets": {
"node": "16"
}
},
"sourceMaps": true
}
8 changes: 8 additions & 0 deletions meta/swc-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@voiceflow-meta/swc-config",
"version": "1.0.0",
"private": true,
"files": [
"base.json"
]
}
25 changes: 25 additions & 0 deletions meta/typescript-config/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Default",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "Node",
"module": "ESNext",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true,
"noImplicitAny": true,
"target": "ES2021",
"paths": {
"@/*": ["./src/*"]
}
}
}
11 changes: 11 additions & 0 deletions meta/typescript-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "@voiceflow-meta/typescript-config",
"version": "1.0.0",
"private": true,
"files": [
"base.json"
],
"dependencies": {
"@voiceflow/tsconfig": "1.4.8"
}
}
25 changes: 9 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"name": "root",
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
Expand All @@ -10,35 +9,25 @@
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/chai": "4.3.0",
"@types/chai-as-promised": "^7.1.5",
"@types/mocha": "^8.2.2",
"@types/node": "16.11.12",
"@types/sinon": "^10.0.13",
"@types/sinon-chai": "^3.2.9",
"@voiceflow/commitlint-config": "2.1.0",
"@voiceflow/eslint-config": "6.1.0",
"@voiceflow/git-branch-check": "1.4.1",
"@voiceflow/prettier-config": "1.3.0",
"@voiceflow/tsconfig": "1.4.8",
"chai": "4.3.6",
"chai-as-promised": "^7.1.1",
"commitizen": "4.2.4",
"cz-conventional-changelog": "3.3.0",
"depcheck": "^1.4.1",
"eslint": "8.19.0",
"eslint-output": "^3.0.1",
"fixpack": "^4.0.0",
"husky": "^4.3.8",
"jest": "29.3.1",
"lerna": "^4.0.0",
"lint-staged": "^11.0.0",
"mocha": "9.2.2",
"npm-run-all": "4.1.5",
"nyc": "^15.1.0",
"prettier": "^2.3.0",
"rimraf": "^3.0.2",
"sinon": "^14.0.2",
"sinon-chai": "^3.7.0",
"source-map-support": "^0.5.19",
"ts-mocha": "^8.0.0",
"ts-node": "10.9.0",
"tsc-alias": "1.8.8",
"tsconfig-paths": "4.0.0",
Expand All @@ -55,8 +44,8 @@
"strip-ansi": "6.0.1"
},
"scripts": {
"build:all": "yarn build",
"build": "turbo run build",
"build:all": "yarn build",
"clean": "yarn clean:artifacts && yarn clean:root",
"clean:artifacts": "turbo run clean",
"clean:root": "rimraf node_modules",
Expand All @@ -72,6 +61,7 @@
"g:depcheck": "cd $INIT_CWD && depcheck",
"g:eslint": "cd $INIT_CWD && eslint",
"g:eslint-output": "cd $INIT_CWD && eslint-output",
"g:jest": "cd $INIT_CWD && jest",
"g:nyc": "cd $INIT_CWD && nyc",
"g:rimraf": "cd $INIT_CWD && rimraf",
"g:run-p": "cd $INIT_CWD && run-p",
Expand All @@ -82,7 +72,10 @@
"node": "20.10.0",
"yarn": "3.2.1"
},
"workspaces": [
"packages/*"
]
"workspaces": {
"packages": [
"packages/*",
"meta/*"
]
}
}
7 changes: 5 additions & 2 deletions packages/alexa-types/.depcheckrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"specials": ["bin"],
"specials": [
"bin"
],
"ignores": [
"@alexa-types/*",
"@types/*"
"@types/*",
"@voiceflow-meta/typescript-config"
]
}
7 changes: 5 additions & 2 deletions packages/alexa-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"@voiceflow/voiceflow-types": "workspace:*",
"ask-smapi-model": "1.14.0"
},
"devDependencies": {
"@voiceflow-meta/typescript-config": "workspace:*"
},
"files": [
"build"
],
Expand All @@ -34,8 +37,8 @@
},
"scripts": {
"build": "yarn clean && yarn build:cjs && yarn build:esm",
"build:cjs": "yarn g:tsc -p tsconfig.build.json && yarn g:tsc-alias -p tsconfig.build.json && yarn postbuild:cjs",
"build:esm": "yarn g:tsc -p tsconfig.esm.json && yarn g:tsc-alias -p tsconfig.esm.json && yarn postbuild:esm",
"build:cjs": "yarn g:tsc -p tsconfig.build.cjs.json && yarn g:tsc-alias -p tsconfig.build.cjs.json && yarn postbuild:cjs",
"build:esm": "yarn g:tsc -p tsconfig.build.esm.json && yarn g:tsc-alias -p tsconfig.build.esm.json && yarn postbuild:esm",
"clean": "yarn g:rimraf build",
"lint": "yarn g:eslint '**/*.{js,ts}'",
"lint:fix": "yarn lint --fix",
Expand Down
7 changes: 7 additions & 0 deletions packages/alexa-types/tsconfig.build.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "build/cjs"
}
}
File renamed without changes.
14 changes: 0 additions & 14 deletions packages/alexa-types/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,4 @@
{
"extends": "./tsconfig.json",
"references": [
{
"path": "../base-types/tsconfig.build.json"
},
{
"path": "../common/tsconfig.build.json"
},
{
"path": "../voice-types/tsconfig.build.json"
},
{
"path": "../voiceflow-types/tsconfig.build.json"
}
],
"include": ["src"]
}
24 changes: 0 additions & 24 deletions packages/alexa-types/tsconfig.esm.json

This file was deleted.

5 changes: 2 additions & 3 deletions packages/alexa-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"extends": "@voiceflow/tsconfig/monorepo.json",
"extends": "@voiceflow-meta/typescript-config/base.json",
"compilerOptions": {
"exactOptionalPropertyTypes": false,
"baseUrl": ".",
"rootDir": "src",
"outDir": "build/cjs",
"paths": {
"@alexa-types/*": ["src/*"]
},
"types": ["mocha"]
}
},
"exclude": ["node_modules", "build"]
}
8 changes: 6 additions & 2 deletions packages/api-sdk/.depcheckrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"specials": ["bin", "istanbul"],
"specials": [
"bin",
"istanbul"
],
"ignores": [
"@types/*",
"@api-sdk/*",
"chai",
"chai-as-promised",
"sinon",
"source-map-support"
"source-map-support",
"@voiceflow-meta/typescript-config"
]
}
16 changes: 0 additions & 16 deletions packages/api-sdk/.nycrc.json

This file was deleted.

6 changes: 6 additions & 0 deletions packages/api-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const config = require('@voiceflow-meta/jest-config');

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...config,
};
8 changes: 5 additions & 3 deletions packages/api-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"devDependencies": {
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^18.11.11",
"@voiceflow-meta/jest-config": "workspace:*",
"@voiceflow-meta/typescript-config": "workspace:*",
"jsonwebtoken": "^8.5.1"
},
"files": [
Expand All @@ -38,8 +40,8 @@
},
"scripts": {
"build": "yarn clean && yarn build:cjs && yarn build:esm",
"build:cjs": "yarn g:tsc -p tsconfig.build.json && yarn g:tsc-alias -p tsconfig.build.json && yarn postbuild:cjs",
"build:esm": "yarn g:tsc -p tsconfig.esm.json && yarn g:tsc-alias -p tsconfig.esm.json && yarn postbuild:esm",
"build:cjs": "yarn g:tsc -p tsconfig.build.cjs.json && yarn g:tsc-alias -p tsconfig.build.cjs.json && yarn postbuild:cjs",
"build:esm": "yarn g:tsc -p tsconfig.build.esm.json && yarn g:tsc-alias -p tsconfig.build.esm.json && yarn postbuild:esm",
"clean": "yarn g:rimraf build",
"lint": "yarn g:eslint '**/*.{js,ts}'",
"lint:fix": "yarn lint --fix",
Expand All @@ -49,7 +51,7 @@
"postbuild:esm": "touch build/esm/package.json && echo '{ \"type\": \"module\" }' > build/esm/package.json",
"tdd": "yarn test:unit --watch",
"test:dependencies": "yarn g:depcheck",
"test:unit": "NODE_ENV=test yarn g:nyc --report-dir=nyc_coverage_unit ts-mocha --paths --config ./config/tests/.mocharc.json 'tests/**/*.unit.ts'"
"test:unit": "yarn g:jest"
},
"types": "build/cjs/index.d.ts"
}
7 changes: 5 additions & 2 deletions packages/api-sdk/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
sonar.projectName=libs-api-sdk
sonar.sources=src
sonar.tests=tests
sonar.tests=src/
sonar.exclusions=src/**/*.test.ts,src/**/test-utils/
sonar.test.inclusions=src/**/*.test.ts,src/**/test-utils/
sonar.cpd.exclusions=src/**/*.test.ts,src/**/test-utils/
sonar.eslint.reportPaths=sonar/report.json
sonar.typescript.tsconfigPath=./tsconfig.json
sonar.javascript.lcov.reportPaths=nyc_coverage_unit/lcov.info
sonar.javascript.lcov.reportPaths=nyc_coverage_unit/lcov.info
Loading

0 comments on commit ab7c8b4

Please sign in to comment.