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

Unify rollup configs #800

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/fuzzy-months-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
51 changes: 41 additions & 10 deletions config/rollup/rollup-utils.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
import path from 'path';

import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import excludeDependenciesFromBundle from 'rollup-plugin-exclude-dependencies-from-bundle';

export function getPlugins(outDir) {
export function getPlugins({
outDir,
tsconfig,
minify,
replacements,
bundleDependencies = false,
}) {
return [
excludeDependenciesFromBundle({dependencies: true, peerDependencies: true}),
...(bundleDependencies
? []
: [
excludeDependenciesFromBundle({
dependencies: true,
peerDependencies: true,
}),
]),
resolve({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
}),
replace({
preventAssignment: true,
...(replacements ?? {}),
}),
commonjs(),
typescript({
tsconfig: path.resolve('./tsconfig.build.json'),
tsconfig: tsconfig ? tsconfig : './tsconfig.build.json',
outDir,
outputToFilesystem: false,
noEmit: true,
declaration: false,
moduleResolution: 'Bundler',
}),
...(minify === true ? [terser({keep_fnames: new RegExp('fetch')})] : []),
];
}

Expand All @@ -45,19 +59,36 @@ export const cjsConfigs = {
exports: 'named',
};

export function getConfig(pkg, input = 'src/index.ts') {
export function getConfig({
pkg,
minify,
tsconfig,
replacements,
input = 'src/index.ts',
flatOutput = false,
}) {
return [
{
input,
plugins: getPlugins('./dist/esm'),
plugins: getPlugins({
outDir: flatOutput ? './dist' : './dist/esm',
minify,
tsconfig,
replacements,
}),
external: Object.keys(pkg.dependencies),
output: [esmConfigs],
output: [{...esmConfigs, dir: flatOutput ? './dist' : './dist/esm'}],
},
{
input,
plugins: getPlugins('./dist/cjs'),
plugins: getPlugins({
outDir: flatOutput ? './dist' : './dist/cjs',
minify,
tsconfig,
replacements,
}),
external: Object.keys(pkg.dependencies),
output: [cjsConfigs],
output: [{...cjsConfigs, dir: flatOutput ? './dist' : './dist/cjs'}],
},
];
}
2 changes: 1 addition & 1 deletion packages/api-clients/admin-api-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"scripts": {
"lint": "eslint . --ext .js,.ts",
"build": "yarn run rollup",
"build": "yarn tsc -p ./tsconfig.build.json && yarn run rollup",
"test": "jest",
"test:ci": "yarn test",
"rollup": "rollup -c --bundleConfigAsCjs",
Expand Down
70 changes: 12 additions & 58 deletions packages/api-clients/admin-api-client/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -1,64 +1,18 @@
import dts from "rollup-plugin-dts";
import typescript from "@rollup/plugin-typescript";
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
import replace from "@rollup/plugin-replace";
import dts from 'rollup-plugin-dts';

import * as pkg from "./package.json";
import * as pkg from './package.json';
import {getConfig} from '../../../config/rollup/rollup-utils';

export const mainSrcInput = "src/index.ts";

export function getPlugins({ tsconfig, minify } = {}) {
return [
replace({
preventAssignment: true,
ROLLUP_REPLACE_CLIENT_VERSION: pkg.version,
}),
resolve(),
commonjs(),
typescript({
tsconfig: tsconfig ? tsconfig : "./tsconfig.build.json",
outDir: "./dist/ts",
}),
...(minify === true ? [terser({ keep_fnames: new RegExp("fetch") })] : []),
];
}

const config = [
{
input: mainSrcInput,
plugins: getPlugins(),
output: [
{
dir: "./dist",
format: "es",
sourcemap: true,
preserveModules: true,
preserveModulesRoot: "src",
entryFileNames: "[name].mjs",
},
],
},
export default [
...getConfig({
pkg,
input: 'src/index.ts',
replacements: {ROLLUP_REPLACE_CLIENT_VERSION: pkg.version},
flatOutput: true,
}),
{
input: mainSrcInput,
plugins: getPlugins(),
output: [
{
dir: "./dist",
format: "cjs",
sourcemap: true,
exports: "named",
preserveModules: true,
preserveModulesRoot: "src",
},
],
},
{
input: "./dist/ts/index.d.ts",
output: [{ file: "dist/admin-api-client.d.ts", format: "es" }],
input: './dist/ts/index.d.ts',
output: [{file: 'dist/admin-api-client.d.ts', format: 'es'}],
plugins: [dts.default()],
},
];

export default config;
5 changes: 5 additions & 0 deletions packages/api-clients/admin-api-client/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "dist/ts",
},
"extends": "./tsconfig.json",
"exclude": ["./node_modules", "./src/**/tests/*.ts"]
}
2 changes: 1 addition & 1 deletion packages/api-clients/admin-api-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"declaration": true,
"declarationMap": true,
"target": "ES2022",
"lib": ["ESNext"],
"lib": ["ESNext", "DOM"],
"rootDir": "src",
"baseUrl": "src",
"strict": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-clients/api-codegen-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"scripts": {
"lint": "eslint . --ext .js,.ts",
"build": "yarn run rollup",
"build": "yarn tsc -p ./tsconfig.build.json && yarn run rollup",
"test": "jest",
"test:ci": "yarn test",
"rollup": "rollup -c --bundleConfigAsCjs",
Expand Down
62 changes: 7 additions & 55 deletions packages/api-clients/api-codegen-preset/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,17 @@
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';

import * as pkg from './package.json';
import {getConfig} from '../../../config/rollup/rollup-utils';

export const mainSrcInput = 'src/index.ts';

export function getPlugins({tsconfig, minify} = {}) {
return [
replace({
preventAssignment: true,
}),
resolve(),
commonjs(),
typescript({
tsconfig: tsconfig ? tsconfig : './tsconfig.build.json',
outDir: './dist/ts',
}),
...(minify === true ? [terser({keep_fnames: new RegExp('fetch')})] : []),
];
}

const config = [
{
input: mainSrcInput,
plugins: getPlugins(),
external: Object.keys(pkg.dependencies),
output: [
{
dir: './dist',
format: 'es',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].mjs',
},
],
},
{
input: mainSrcInput,
plugins: getPlugins(),
external: Object.keys(pkg.dependencies),
output: [
{
dir: './dist',
format: 'cjs',
sourcemap: true,
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src',
},
],
},
export default [
...getConfig({
pkg,
input: 'src/index.ts',
flatOutput: true,
}),
{
input: './dist/ts/index.d.ts',
output: [{file: 'dist/index.d.ts', format: 'es'}],
plugins: [dts.default()],
},
];

export default config;
7 changes: 7 additions & 0 deletions packages/api-clients/api-codegen-preset/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"emitDeclarationOnly": true,
"moduleResolution": "Bundler",
"module": "Preserve",
"outDir": "dist/ts",
},
"extends": "./tsconfig.json",
"exclude": ["./node_modules", "./src/**/tests/*.ts"]
}
2 changes: 1 addition & 1 deletion packages/api-clients/graphql-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"scripts": {
"lint": "eslint . --ext .js,.ts",
"build": "yarn run rollup",
"build": "yarn tsc -p ./tsconfig.build.json && yarn run rollup",
"test": "jest",
"test:ci": "yarn test",
"rollup": "rollup -c --bundleConfigAsCjs",
Expand Down
61 changes: 13 additions & 48 deletions packages/api-clients/graphql-client/rollup.config.cjs
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
import dts from 'rollup-plugin-dts';
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import replace from '@rollup/plugin-replace';

import {getConfig, getPlugins} from '../../../config/rollup/rollup-utils';

import * as pkg from './package.json';

const mainSrcInput = 'src/index.ts';
const clientSrcInput = 'src/graphql-client/index.ts';

export function getPlugins({tsconfig, minify} = {}) {
return [
replace({
preventAssignment: true,
ROLLUP_REPLACE_CLIENT_VERSION: pkg.version,
}),
resolve(),
commonjs(),
typescript({
tsconfig: tsconfig ? tsconfig : './tsconfig.json',
outDir: './dist/ts',
}),
...(minify === true ? [terser({keep_fnames: new RegExp('fetch')})] : []),
];
}

const packageName = pkg.name.substring(1);
export const bannerConfig = {
banner: `/*! ${packageName}@${pkg.version} -- Copyright (c) 2023-present, Shopify Inc. -- license (MIT): https://github.com/Shopify/shopify-app-js/blob/main/LICENSE.md */`,
Expand All @@ -35,8 +16,11 @@ const config = [
{
input: clientSrcInput,
plugins: getPlugins({
outDir: './dist/ts',
minify: true,
tsconfig: './tsconfig.umd.json',
replacements: {ROLLUP_REPLACE_CLIENT_VERSION: pkg.version},
bundleDependencies: true,
}),
output: [
{
Expand All @@ -51,7 +35,10 @@ const config = [
{
input: clientSrcInput,
plugins: getPlugins({
outDir: './dist/ts',
tsconfig: './tsconfig.umd.json',
replacements: {ROLLUP_REPLACE_CLIENT_VERSION: pkg.version},
bundleDependencies: true,
}),
output: [
{
Expand All @@ -63,34 +50,12 @@ const config = [
},
],
},
{
input: mainSrcInput,
plugins: getPlugins(),
output: [
{
dir: './dist',
format: 'es',
sourcemap: true,
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].mjs',
},
],
},
{
...getConfig({
pkg,
input: mainSrcInput,
plugins: getPlugins(),
output: [
{
dir: './dist',
format: 'cjs',
sourcemap: true,
exports: 'named',
preserveModules: true,
preserveModulesRoot: 'src',
},
],
},
flatOutput: true,
replacements: {ROLLUP_REPLACE_CLIENT_VERSION: pkg.version},
}),
{
input: './dist/ts/index.d.ts',
output: [{file: 'dist/graphql-client.d.ts', format: 'es'}],
Expand Down
Loading
Loading