Skip to content

Commit

Permalink
adding cjs and mjs builds (wpengine#412)
Browse files Browse the repository at this point in the history
* adding cjs and mjs builds

* fix: using single package script
  • Loading branch information
wjohnsto authored Aug 24, 2021
1 parent 2dba521 commit b5c220e
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 118 deletions.
15 changes: 12 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@
"name": "@faustjs/core",
"version": "0.8.0",
"description": "This module helps you use WordPress as a Headless CMS",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
"types": "dist/cjs/index.d.ts",
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"scripts": {
"build": "npm run clean && npm run ts",
"build": "npm run clean && npm run ts && npm run ts:cjs && npm run package",
"dev": "npm run ts:watch",
"dev-lerna": "npm run dev",
"clean": "rimraf dist",
"package": "node ../../scripts/package.js",
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" --parser-options=project:tsconfig.json --fix",
"lint": "eslint \"src/**/*.{ts,tsx}\" --parser-options=project:tsconfig.json",
"prepublish": "npm run build",
"generate:gqty": "gqty generate",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"ts": "tsc -p .",
"ts:cjs": "tsc -p tsconfig-cjs.json",
"ts:watch": "tsc -p . --watch"
},
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2019",
"rootDir": "src"
}
}
46 changes: 9 additions & 37 deletions packages/core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,11 @@
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ES2019",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"noUnusedLocals": true,
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"typeRoots": [
"src/types",
"node_modules/@types",
"../../node_modules/@types"
]
},
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "../../docs/reference/api/",
"excludeExternals": true
},
"include": [
"src",
"src/types/wpgraphql.d.ts"
],
"exclude": [
"node_modules",
"dist"
]
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs",
"target": "esnext",
"rootDir": "src"
},
"exclude": ["node_modules", "dist"],
"include": ["src"]
}
15 changes: 12 additions & 3 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
"name": "@faustjs/next",
"version": "0.8.0",
"description": "This module helps you use WordPress as a Headless CMS with Next.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
"types": "dist/cjs/index.d.ts",
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"scripts": {
"build": "npm run clean && npm run ts",
"build": "npm run clean && npm run ts && npm run ts:cjs && npm run package",
"dev": "npm run ts:watch",
"dev-lerna": "npm run dev",
"clean": "rimraf dist",
"package": "node ../../scripts/package.js",
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" --parser-options=project:tsconfig.json --fix",
"lint": "eslint \"src/**/*.{ts,tsx}\" --parser-options=project:tsconfig.json",
"prepublish": "npm run build",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"ts": "tsc -p .",
"ts:cjs": "tsc -p tsconfig-cjs.json",
"ts:watch": "tsc -p . --watch"
},
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions packages/next/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2019",
"rootDir": "src"
}
}
46 changes: 10 additions & 36 deletions packages/next/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ES2019",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"noUnusedLocals": true,
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"typeRoots": [
"node_modules/@types",
"../../node_modules/@types"
],
"jsx": "react"
},
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "../../docs/reference/api/",
"excludeExternals": true
},
"include": [
"src"
],
"exclude": [
"node_modules",
"dist"
]
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs",
"target": "esnext",
"rootDir": "src",
"jsx": "react"
},
"exclude": ["node_modules", "dist"],
"include": ["src"]
}
15 changes: 12 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
"name": "@faustjs/react",
"version": "0.8.0",
"description": "This module helps you use WordPress as a Headless CMS with React",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/mjs/index.js",
"types": "dist/cjs/index.d.ts",
"exports": {
".": {
"import": "./dist/mjs/index.js",
"require": "./dist/cjs/index.js"
}
},
"scripts": {
"build": "npm run clean && npm run ts",
"build": "npm run clean && npm run ts && npm run ts:cjs && npm run package",
"dev": "npm run ts:watch",
"dev-lerna": "npm run dev",
"clean": "rimraf dist",
"package": "node ../../scripts/package.js",
"lint:fix": "eslint \"src/**/*.{ts,tsx}\" --parser-options=project:tsconfig.json --fix",
"lint": "eslint \"src/**/*.{ts,tsx}\" --parser-options=project:tsconfig.json",
"prepublish": "npm run build",
"test": "jest --passWithNoTests",
"test:watch": "jest --watch",
"ts": "tsc -p .",
"ts:cjs": "tsc -p tsconfig-cjs.json",
"ts:watch": "tsc -p . --watch"
},
"repository": {
Expand Down
9 changes: 9 additions & 0 deletions packages/react/tsconfig-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "dist/cjs",
"target": "es2019",
"rootDir": "src"
}
}
46 changes: 10 additions & 36 deletions packages/react/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node",
"target": "ES2019",
"removeComments": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true,
"esModuleInterop": true,
"strict": true,
"noUnusedLocals": true,
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"typeRoots": [
"node_modules/@types",
"../../node_modules/@types"
],
"jsx": "react"
},
"typedocOptions": {
"entryPoints": ["src/index.ts"],
"out": "../../docs/reference/api/",
"excludeExternals": true
},
"include": [
"src"
],
"exclude": [
"node_modules",
"dist"
]
"extends": "../../tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "dist/mjs",
"target": "esnext",
"rootDir": "src",
"jsx": "react"
},
"exclude": ["node_modules", "dist"],
"include": ["src"]
}
31 changes: 31 additions & 0 deletions scripts/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const fs = require('fs');
const path = require('path');

const writeFileAsync = (path, data) =>
new Promise((resolve, reject) => {
fs.writeFile(path, data, (err) => {
if (err) {
reject(err);
} else {
resolve();
}
});
});

(async () => {
try {
await writeFileAsync(
path.resolve(process.cwd(), './dist/mjs/package.json'),
'{\n "type": "module"\n}\n',
);
await writeFileAsync(
path.resolve(process.cwd(), './dist/cjs/package.json'),
'{\n "type": "commonjs"\n}\n',
);

process.exit();
} catch (err) {
console.error(err);
process.exit(1);
}
})();
23 changes: 23 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "src",
"declaration": true,
"esModuleInterop": true,
"inlineSourceMap": false,
"lib": ["dom", "dom.iterable", "esnext"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"traceResolution": false,
"types": ["node", "jest"],
"typeRoots": ["node_modules/@types"]
},
"compileOnSave": false
}

0 comments on commit b5c220e

Please sign in to comment.