Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use babel to transpile TS projects #47502

Merged
merged 13 commits into from
Nov 19, 2020
76 changes: 0 additions & 76 deletions bin/watch-packages-and-rebuild.js

This file was deleted.

8 changes: 1 addition & 7 deletions client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@
"calypso/*": [ "./*" ]
}
},
"references": [
{ "path": "../packages/calypso-analytics" },
{ "path": "../packages/components" },
{ "path": "../packages/data-stores" },
{ "path": "../packages/language-picker" },
{ "path": "../packages/react-i18n" }
],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also a packages/languages package that is written in TypeScript and isn't being migrated in this PR: it's still built during the prepare step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/languages is migrated in the sense that has calypso:src, but still requires a build step because we do use it to build Calypso: yarn build-languages calls bin/build-languages.js which requires '@automattic/languages'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, the package is used by a Node.js build script and needs to be built 🙁

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @automattic/languages is in a very similar situation as a Gutenberg webpack plugin we're discussing with @sirreal in WordPress/gutenberg#26382 (comment)

I think we'd be better off if the package was written in plain JavaScript, where it would be a trivial two-liner:

import data from './languages-meta.json';
export default Object.values( data );

and if the types were in a separate index.d.ts file.

Then the package wouldn't need any build step at all, could be directly consumed by Node.js build scripts, and consumers would still get TypeScript types for it without any observable change.

This approach is an exception rather that a rule, but I think it would be justified for certain packages like these I mention.

"references": [ { "path": "../packages" } ],
"include": [ "**/*", "../build-tools/**" ],
"exclude": [
"../**/node_modules/**/*",
Expand Down
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"analyze-icfy": "yarn run build-client-stats && node --max-old-space-size=4096 bin/icfy-analyze.js",
"autoprefixer": "postcss -u autoprefixer -r --no-map --config packages/calypso-build/postcss.config.js",
"postcss": "postcss -r --config packages/calypso-build/postcss.config.js",
"build": "yarn run build-static && yarn run build-packages && yarn run build-css && run-p -s build-devdocs:* && run-p -s build-server build-client-if-prod build-client-if-desktop",
"build": "yarn run build-static && yarn run build-css && run-p -s build-devdocs:* && run-p -s build-server build-client-if-prod build-client-if-desktop",
"build-css": "run-p -s build-css:*",
"build-css:directly": "node-sass --importer node_modules/node-sass-package-importer/dist/cli.js --include-path client client/assets/stylesheets/directly.scss public/directly.css --output-style compressed && yarn run -s postcss public/directly.css",
"build-css:reader-mobile": "node-sass --importer node_modules/node-sass-package-importer/dist/cli.js --include-path client client/assets/stylesheets/reader-mobile.scss public/reader-mobile.css --output-style compressed && yarn run -s postcss public/reader-mobile.css",
Expand Down Expand Up @@ -90,14 +90,13 @@
"build-client-if-prod": "node -e \"process.env.CALYPSO_ENV === 'production' && process.exit(1)\" || yarn run build-client-both && yarn run build-languages-if-enabled",
"build-client-if-desktop": "node -e \"(process.env.CALYPSO_ENV === 'desktop' || process.env.CALYPSO_ENV === 'desktop-development') && process.exit(1)\" || yarn run build-client-fallback",
"build-client-stats": "NODE_ENV=production CALYPSO_ENV=production EMIT_STATS=true PROGRESS=true yarn run build-client-evergreen",
"build-packages": "npx lerna run prepare --stream",
"build-packages:watch": "node bin/watch-packages-and-rebuild.js",
"build-packages": "tsc --build packages/tsconfig.json && lerna run prepare --stream",
"build-languages": "yarn run translate && node bin/build-languages.js",
"build-languages-if-enabled": "node -e \"(process.env.BUILD_TRANSLATION_CHUNKS === 'true' || process.env.ENABLE_FEATURES === 'use-translation-chunks') && process.exit(1)\" || yarn run build-languages",
"calypso-doctor": "./node_modules/.bin/calypso-doctor",
"clean": "yarn run clean:packages && yarn run clean:build && yarn run clean:public && yarn run clean:translations",
"clean:build": "npx rimraf build client/server/bundler/*.json client/server/devdocs/search-index.js",
"clean:packages": "npx lerna run clean --stream",
"clean:packages": "lerna run clean --stream",
"clean:public": "npx rimraf public",
"clean:translations": "npx rimraf build/strings calypso-strings.pot chunks-map.*.json",
"distclean": "yarn run clean && npx rimraf node_modules client/node_modules desktop/node_modules apps/*/node_modules packages/*/node_modules test/e2e/node_modules .cache apps/*/.cache vendor",
Expand All @@ -114,7 +113,7 @@
"lint:package-json": "npmPkgJsonLint './package.json' './client/package.json' './packages/*/package.json' './apps/*/package.json'",
"prestart": "npx check-node-version --package && node bin/welcome.js",
"start": "yarn run -s build",
"poststart": "run-p -s start-build-if-web start-build-if-desktop build-packages:watch",
"poststart": "run-p -s start-build-if-web start-build-if-desktop",
"start-fallback": "DEV_TARGET=fallback yarn run start",
"start-jetpack-cloud": "CALYPSO_ENV=jetpack-cloud-development yarn start",
"start-jetpack-cloud-p": "PORT=3001 CALYPSO_ENV=jetpack-cloud-development yarn run build-server",
Expand Down
11 changes: 6 additions & 5 deletions packages/browser-data-collector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"homepage": "https://github.com/Automattic/wp-calypso",
"license": "GPL-2.0-or-later",
"author": "Automattic Inc.",
"main": "dist/cjs/index",
"module": "dist/esm/index",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Automattic/wp-calypso.git",
Expand All @@ -17,9 +18,9 @@
"url": "https://github.com/Automattic/wp-calypso/issues"
},
"scripts": {
"clean": "tsc --build ./tsconfig.json --clean && tsc --build ./tsconfig-cjs.json --clean",
"prepublish": "yarn run clean",
"prepare": "tsc --build ./tsconfig.json && tsc --build ./tsconfig-cjs.json",
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
Copy link
Contributor Author

@scinos scinos Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsc --build ... --clean deletes the files but lefts lots of empty dirs, that's why I added npx rimraf dist

"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json",
sirreal marked this conversation as resolved.
Show resolved Hide resolved
"prepack": "yarn run clean && yarn run build",
"watch": "tsc --build ./tsconfig.json --watch"
},
"dependencies": {
Expand Down
11 changes: 6 additions & 5 deletions packages/calypso-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"license": "GPL-2.0-or-later",
"author": "Automattic Inc.",
"sideEffects": true,
"main": "dist/cjs/index",
"module": "dist/esm/index",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/Automattic/wp-calypso.git",
Expand All @@ -25,9 +26,9 @@
"url": "https://github.com/Automattic/wp-calypso/issues"
},
"scripts": {
"clean": "tsc --build ./tsconfig.json --clean && tsc --build ./tsconfig-cjs.json --clean",
"prepublish": "yarn run clean",
"prepare": "tsc --build ./tsconfig.json && tsc --build ./tsconfig-cjs.json",
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json",
"prepack": "yarn run clean && yarn run build",
"watch": "tsc --build ./tsconfig.json --watch"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/calypso-stripe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"calypso:src": "index.ts",
"sideEffects": false,
"scripts": {
"clean": "npx rimraf dist && tsc --build ./tsconfig.json --clean && tsc --build ./tsconfig-cjs.json --clean",
"build:esm": "tsc --build ./tsconfig.json",
"build:cjs": "tsc --build ./tsconfig-cjs.json",
"prepare": "yarn run build:esm",
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json",
"prepack": "yarn run clean && yarn run build",
"watch": "tsc --build ./tsconfig.json --watch"
},
"files": [
Expand Down
7 changes: 4 additions & 3 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"author": "Automattic Inc.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.js",
"sideEffects": [
"*.css",
"*.scss"
Expand Down Expand Up @@ -46,8 +47,8 @@
"ts-loader": "^8.0.8"
},
"scripts": {
"clean": "npx rimraf dist && tsc --build --clean",
"prepublish": "yarn run clean",
"prepare": "transpile && tsc --build && copy-assets"
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json && copy-assets",
"prepack": "yarn run clean && yarn run build"
}
}
12 changes: 12 additions & 0 deletions packages/components/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"module": "commonjs",
"declaration": false,
"declarationMap": false,
"declarationDir": null,
"outDir": "dist/cjs",
"composite": false,
"incremental": true
}
}
2 changes: 1 addition & 1 deletion packages/components/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"jsx": "react",
"declaration": true,
"declarationDir": "dist/types",
"outDir": "dist/types",
"outDir": "dist/esm",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fix, esm build was being written to the wrong place 🙂

"isolatedModules": true,

"strict": true,
Expand Down
7 changes: 4 additions & 3 deletions packages/composite-checkout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"main": "dist/cjs/public-api.js",
"module": "dist/esm/public-api.js",
"types": "dist/types/public-api.d.ts",
"calypso:src": "src/public-api.ts",
"sideEffects": false,
"scripts": {
"clean": "npx rimraf dist \"../../.tsc-cache/packages__composite-checkout*\"",
"prepare": "tsc --build ./tsconfig.json && tsc --build ./tsconfig-cjs.json",
"prepublish": "yarn run clean",
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json && copy-assets",
"prepack": "yarn run clean && yarn run build",
"watch": "tsc --build ./tsconfig.json --watch"
},
"files": [
Expand Down
7 changes: 4 additions & 3 deletions packages/data-stores/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"author": "Automattic Inc.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.ts",
"sideEffects": false,
"repository": {
"type": "git",
Expand All @@ -26,9 +27,9 @@
],
"types": "dist/types",
"scripts": {
"clean": "tsc --build ./tsconfig.json --clean && tsc --build ./tsconfig-cjs.json --clean",
"prepare": "tsc --build ./tsconfig.json && tsc --build ./tsconfig-cjs.json",
"prepublish": "yarn run clean",
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json && copy-assets",
"prepack": "yarn run clean && yarn run build",
"watch": "tsc --build ./tsconfig.json --watch"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-stores/src/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type { DispatchFromMap, SelectFromMap } from '../mapped-types';
import { controls as wpcomRequestControls } from '../wpcom-request-controls';

export * from './types';
export { State };
export type { State };

let isRegistered = false;
export function register( config: ActionsConfig ): typeof STORE_KEY {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-stores/src/domain-suggestions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { DispatchFromMap, SelectFromMap } from '../mapped-types';
import { controls } from '../wpcom-request-controls';

export * from './types';
export { State };
export type { State };

let isRegistered = false;
interface StoreConfiguration {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-stores/src/site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { WpcomClientCredentials } from '../shared-types';
import { controls } from '../wpcom-request-controls';

export * from './types';
export { State };
export type { State };

let isRegistered = false;
export function register( clientCreds: WpcomClientCredentials ): typeof STORE_KEY {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-stores/src/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { DispatchFromMap, SelectFromMap } from '../mapped-types';
import type { WpcomClientCredentials } from '../shared-types';

export * from './types';
export { State };
export type { State };

let isRegistered = false;
export function register( clientCreds: WpcomClientCredentials ): typeof STORE_KEY {
Expand Down
2 changes: 1 addition & 1 deletion packages/data-stores/src/verticals-templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as selectors from './selectors';
import type { DispatchFromMap, SelectFromMap } from '../mapped-types';

export * from './types';
export { State };
export type { State };

let isRegistered = false;
export function register(): typeof STORE_KEY {
Expand Down
7 changes: 4 additions & 3 deletions packages/domain-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"author": "Automattic Inc.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.tsx",
"sideEffects": [
"*.css",
"*.scss"
Expand All @@ -24,9 +25,9 @@
},
"types": "dist/types",
"scripts": {
"clean": "tsc --build ./tsconfig.json --clean && tsc --build ./tsconfig-cjs.json --clean",
"prepare": "tsc --build ./tsconfig.json && tsc --build ./tsconfig-cjs.json && copy-assets",
"prepublish": "yarn run clean",
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json && copy-assets",
"prepack": "yarn run clean && yarn run build",
"watch": "tsc --build ./tsconfig.json --watch"
},
"dependencies": {
Expand Down
4 changes: 3 additions & 1 deletion packages/domain-picker/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Internal dependencies
*/
export { default, Props } from './domain-picker';
export { default } from './domain-picker';
export type { Props } from './domain-picker';

export { ITEM_TYPE_RADIO, ITEM_TYPE_BUTTON } from './domain-picker/suggestion-item';
export type { SUGGESTION_ITEM_TYPE } from './domain-picker/suggestion-item';
7 changes: 4 additions & 3 deletions packages/i18n-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "WordPress.com i18n utils",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.ts",
"types": "dist/types/index.d.ts",
"sideEffects": false,
"license": "GPL-2.0-or-later",
Expand All @@ -14,9 +15,9 @@
},
"author": "Automattic Inc.",
"scripts": {
"clean": "npx rimraf dist",
"prepublish": "yarn run clean",
"prepare": "tsc --build ./tsconfig.json && tsc --build ./tsconfig-cjs.json",
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json",
"prepack": "yarn run clean && yarn run build",
"watch": "tsc --build ./tsconfig.json --watch",
"download": "node bin/download.js",
"test": "yarn jest"
Expand Down
9 changes: 4 additions & 5 deletions packages/language-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"author": "Automattic Inc.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"calypso:src": "src/index.ts",
"sideEffects": [
"*.css",
"*.scss"
Expand Down Expand Up @@ -40,10 +41,8 @@
"react-dom": "^16.8"
},
"scripts": {
"clean": "npx rimraf dist && tsc --build ./tsconfig.json --clean && tsc --build ./tsconfig-cjs.json --clean",
"build:esm": "tsc --build ./tsconfig.json && copy-assets --esm",
"build:cjs": "tsc --build ./tsconfig-cjs.json && copy-assets --cjs",
"prepare": "yarn run build:esm",
"prepack": "yarn run clean && yarn run build:esm && yarn run build:cjs"
"clean": "tsc --build ./tsconfig.json ./tsconfig-cjs.json --clean && npx rimraf dist",
"build": "tsc --build ./tsconfig.json ./tsconfig-cjs.json",
"prepack": "yarn run clean && yarn run build"
}
}
Loading