From dfebcbe9a59b03255ae16362701d4a5a2a5b593e Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 30 Sep 2021 11:13:13 +0100 Subject: [PATCH 01/40] feat(preset-rollup): provide a preset for code bundling via rollup --- .presetterrc.json | 9 ++ README.md | 192 +++++++++++++++++++++++++++++++ configs/rollup.yaml | 26 +++++ package.json | 53 +++++++++ source/index.ts | 72 ++++++++++++ source/plugin.ts | 117 +++++++++++++++++++ source/rollup.ts | 224 +++++++++++++++++++++++++++++++++++++ spec/index.spec.ts | 52 +++++++++ spec/plugin.spec.ts | 101 +++++++++++++++++ spec/rollup.spec.ts | 220 ++++++++++++++++++++++++++++++++++++ templates/rollup.config.ts | 3 + templates/scripts.yaml | 5 + 12 files changed, 1074 insertions(+) create mode 100644 .presetterrc.json create mode 100644 README.md create mode 100644 configs/rollup.yaml create mode 100644 package.json create mode 100644 source/index.ts create mode 100644 source/plugin.ts create mode 100644 source/rollup.ts create mode 100644 spec/index.spec.ts create mode 100644 spec/plugin.spec.ts create mode 100644 spec/rollup.spec.ts create mode 100644 templates/rollup.config.ts create mode 100644 templates/scripts.yaml diff --git a/.presetterrc.json b/.presetterrc.json new file mode 100644 index 0000000..e33a3fe --- /dev/null +++ b/.presetterrc.json @@ -0,0 +1,9 @@ +{ + "preset": "presetter-preset", + "config": { + "npmignore": ["!/configs/**", "!/templates/**"] + }, + "variable": { + "root": "../.." + } +} diff --git a/README.md b/README.md new file mode 100644 index 0000000..98c731d --- /dev/null +++ b/README.md @@ -0,0 +1,192 @@ +
+ +![Logo](https://github.com/alvis/presetter/raw/master/assets/logo.svg) + +🏄🏻 _A collection of opinionated configurations for a building a code bundle via rollup for presetter_ + +•   [Quick Start](#quick-start)   •   [Project Structure](#project-structure)   •   [Customisation](#customisation)   •   [Scripts](#script-template-summary)   • + +[![npm](https://img.shields.io/npm/v/presetter-preset-rollup?style=flat-square)](https://github.com/alvis/presetter/releases) +[![build](https://img.shields.io/github/workflow/status/alvis/presetter/code%20test?style=flat-square)](https://github.com/alvis/presetter/actions) +[![maintainability](https://img.shields.io/codeclimate/maintainability/alvis/presetter?style=flat-square)](https://codeclimate.com/github/alvis/presetter/maintainability) +[![coverage](https://img.shields.io/codeclimate/coverage/alvis/presetter?style=flat-square)](https://codeclimate.com/github/alvis/presetter/test_coverage) +[![security](https://img.shields.io/snyk/vulnerabilities/github/alvis/presetter/packages/preset-rollup/package.json.svg?style=flat-square)](https://snyk.io/test/github/alvis/presetter?targetFile=packages/preset-rollup/package.json&style=flat-square) +[![dependencies](https://img.shields.io/david/alvis/presetter?path=packages/preset-rollup&style=flat-square)](https://david-dm.org/alvis/presetter?path=packages/preset-rollup) +[![license](https://img.shields.io/github/license/alvis/presetter.svg?style=flat-square)](https://github.com/alvis/presetter/blob/master/LICENSE) + +
+ +## Features + +**presetter-preset-rollup** is an opinionated preset for you to setup rollup in a fraction of time you usually take via [**presetter**](https://github.com/alvis/presetter). + +- 🗞️ Rollup 2 +- 2️⃣ Dual CJS and ESM modules export by default +- 🍄 Common rollup packages included as one single bundle + - `@rollup/plugin-commonjs` + - `@rollup/plugin-graphql` + - `@rollup/plugin-image` + - `@rollup/plugin-json` + - `@rollup/plugin-yaml` + - `rollup` <~ of course including rollup itself + - `rollup-plugin-postcss` + - `rollup-plugin-ts` + - `rollup-plugin-tsconfig-paths` + - `rollup-plugin-visualizer` + +## Quick Start + +[**FULL DOCUMENTATION IS AVAILABLE HERE**](https://github.com/alvis/presetter/blob/master/README.md) + +1. Bootstrap your project with `presetter-preset` & `presetter-preset-rollup` + +```shell +npx presetter use presetter-preset presetter-preset-rollup +``` + +That's. One command and you're set. + +After bootstrapping, you would see a lot of configuration files generated, including a `rollup.config.ts` that has all plugins configured properly for you. + +2. Develop and run life cycle scripts provided by the preset + +At this point, all development packages specified in the preset are installed, +and now you can try to run some example life cycle scripts (e.g. run prepare). + +![Demo](https://raw.githubusercontent.com/alvis/presetter/master/assets/demo.gif) + +**IMPORTANT** +For NodeJS to import the correct export, remember to specify the following in your project's package.json too! + +```json +{ + "main": "lib/index.js", + "module": "lib/index.mjs", + "types": "lib/index.d.ts", + "exports": { + "require": "./lib/index.js", + "import": "./lib/index.mjs" + } +} +``` + +## Project Structure + +After installing `presetter-preset` & `presetter-preset-rollup`, your project file structure should look like the following or with more configuration file if you also installed `presetter-preset`. + +Implement your business logic under `source` and prepare tests under `spec`. + +**TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `.presetterrc.json`. See the [customisation](https://github.com/alvis/presetter/blob/master/packages/preset-rollup#customisation) section below for more details. + +``` +(root) + ├─ .git + ├─ .preseterrc.json + ├─ node_modules + ├─ source + │ ├─ + │ ├─ index.ts + │ ├─ (auxiliary).ts + ├─ spec + │ ├─ *.spec.ts + ├─ package.json + └─ rollup.config.ts +``` + +## Customisation + +By default, this preset exports a handy configuration for rollup for a typescript project. +But you can further customise (either extending or replacing) the configuration by specifying the change in the config file (`.presetterrc` or `.presetterrc.json`). + +These settings are available in the `config` field in the config file. For directories, the setting is specified in the `variable` field. + +The structure of `.presetterrc` should follow the interface below: + +```ts +interface PresetterRC { + /** name(s) of the preset e.g. presetter-preset */ + name: string | string[]; + /** additional configuration passed to the preset for generating the configuration files */ + config?: { + // ┌─ configuration for other tools via other presets (e.g. presetter-preset) + // ... + + /** additional configuration for rollup */ + rollup?: { + // ┌─ any configuration supported by rollup, see https://rollupjs.org/guide/en/#configuration-files + // ... + + /** list of plugin and its options */ + plugins?: + | NormalisedRollupConfig['plugins'] + | Array< + | string + | [name: string] + | [ + name: string, + options: + | Record + | `@apply ${string}` + | `@import ${string}` + | null, + ] + >; + }; + }; + /** variables to be substituted in templates */ + variable?: { + /** the directory containing all source code (default: source) */ + source?: string; + /** the directory containing all output tile (default: source) */ + output?: string; + }; +} +``` + +For generating `rollup.config.ts`, this preset also support the `@apply` and `@import` directives such that you can also import configuration from other packages or ts/js files. + +The usage of the directives is simple. In any part of the configuration for rollup, you can simply put +`@apply package_name` or `@import package_name` and the preset will automatically replace the content with an imported variable. For example: + +```json +{ + "rollup": { + "plugins": [ + [ + "@apply rollup-plugin-postcss[default]", + { "plugins": "@import ./postcss.config[default.plugins]" } + ] + ] + } +} +``` + +will create a `rollup.config.ts` file with the following content: + +```ts +import * as import0 from 'rollup-plugin-postcss'; +import * as import1 from './postcss.config'; + +export default { + plugins: [import0.default(...[{ plugins: import1.default.plugins }])], +}; +``` + +The syntax for both the directives is quite similar. +Use `@apply` in a situation that you have to invoke a function from an imported package, +such as `rollup-plugin-postcss` in the above example. +You can also specify the arguments for the invoked function in the form of `["@apply package", options]` + +For `@import`, use it if you want to import value from another package or ts/js file. +For example, `@import ./postcss.config[default.plugins]` would allow you to refer `default.plugins` from `./postcss.config` in the above example. + +In addition to the directives, to specify the plugins for rollup, you can write it in three ways similar to babel. + +1. A object with plugin name as the key and its options as its value e.g. `{'@apply @rollup/plugin-typescript[default]': {options}}` +2. Name of a plugin in an array e.g. `['@apply @rollup/plugin-typescript[default]']` +3. Doublet of `[plugin name, options]` in an array e.g. `[['@apply @rollup/plugin-typescript[default]', {options}]]` + +## Script Template Summary + +- **`run build`**: Bundle your code via rollup +- **`run develop`**: Continuous code build and watch diff --git a/configs/rollup.yaml b/configs/rollup.yaml new file mode 100644 index 0000000..035d5b5 --- /dev/null +++ b/configs/rollup.yaml @@ -0,0 +1,26 @@ +input: '{source}/index.ts' +output: + - file: '{output}/index.js' + format: cjs + sourcemap: true + - file: '{output}/index.mjs' + format: es + sourcemap: true +plugins: + - '@apply rollup-plugin-ts[default]' + - '@apply rollup-plugin-tsconfig-paths[default]' + - '@apply @rollup/plugin-node-resolve[default]' + - - '@apply @rollup/plugin-commonjs[default]' + - extensions: + - .js + - .jsx + - .ts + - .tsx + - '@apply @rollup/plugin-json[default]' + - '@apply @rollup/plugin-graphql[default]' + - '@apply @rollup/plugin-image[default]' + - '@apply @rollup/plugin-yaml[default]' + - - '@apply rollup-plugin-postcss[default]' + - inject: + insertAt: top + - '@apply rollup-plugin-visualizer[default]' diff --git a/package.json b/package.json new file mode 100644 index 0000000..2bfafed --- /dev/null +++ b/package.json @@ -0,0 +1,53 @@ +{ + "name": "presetter-preset-rollup", + "version": "0.0.0", + "description": "An opinionated presetter preset for using rollup as a bundler", + "keywords": [ + "presetter", + "preset" + ], + "homepage": "https://github.com/alvis/presetter#readme", + "bugs": { + "url": "https://github.com/alvis/presetter/issues" + }, + "license": "MIT", + "author": { + "name": "Alvis HT Tang", + "email": "alvis@hilbert.space" + }, + "main": "lib/index.js", + "types": "lib/index.d.ts", + "repository": { + "type": "git", + "url": "git+https://github.com/alvis/presetter.git" + }, + "scripts": { + "bootstrap": "presetter bootstrap && run prepare", + "build": "run build", + "coverage": "run coverage", + "lint": "run lint", + "prepublishOnly": "run prepare && run prepublishOnly", + "release": "run-s release:peer:*", + "release:peer:presetter": "npm pkg set peerDependencies.presetter=^$(npx -c 'echo $npm_package_version')", + "test": "run test", + "watch": "run watch" + }, + "peerDependencies": { + "@rollup/plugin-commonjs": "^20.0.0", + "@rollup/plugin-graphql": "^1.0.0", + "@rollup/plugin-image": "^2.0.0", + "@rollup/plugin-json": "^4.0.0", + "@rollup/plugin-node-resolve": "^13.0.0", + "@rollup/plugin-yaml": "^3.0.0", + "presetter": "^3.0.0", + "rollup": "^2.0.0", + "rollup-plugin-postcss": "^4.0.0", + "rollup-plugin-ts": "^1.0.0", + "rollup-plugin-tsconfig-paths": "^1.0.0", + "rollup-plugin-visualizer": "^5.0.0" + }, + "devDependencies": { + "presetter": "file:../presetter", + "presetter-preset": "file:../preset" + } +} diff --git a/source/index.ts b/source/index.ts new file mode 100644 index 0000000..65723b7 --- /dev/null +++ b/source/index.ts @@ -0,0 +1,72 @@ +/* + * *** MIT LICENSE *** + * ------------------------------------------------------------------------- + * This code may be modified and distributed under the MIT license. + * See the LICENSE file for details. + * ------------------------------------------------------------------------- + * + * @summary Collection of preset assets for bundling a project with rollup + * + * @author Alvis HT Tang + * @license MIT + * @copyright Copyright (c) 2021 - All Rights Reserved. + * ------------------------------------------------------------------------- + */ + +import { resolve } from 'path'; +import { loadFile, template } from 'presetter'; + +import { getRollupParameter } from './rollup'; + +import type { PresetAsset } from 'presetter'; + +import type { RollupConfig } from './rollup'; + +// paths to the template directory +const TEMPLATES = resolve(__dirname, '..', 'templates'); +const CONFIGS = resolve(__dirname, '..', 'configs'); + +/** config for this preset */ +export type PresetConfig = { + rollup?: RollupConfig; +}; + +/** List of configurable variables */ +export type Variable = { + /** the directory containing all source code (default: source) */ + source: string; + /** the directory containing all the compiled files (default: lib) */ + output: string; +}; + +export const DEFAULT_VARIABLE: Variable = { + source: 'source', + output: 'lib', +}; + +/** + * get the list of templates provided by this preset + * @returns list of preset templates + */ +export default async function (): Promise { + return { + template: { + 'rollup.config.ts': async (context) => { + const content = await loadFile( + resolve(TEMPLATES, 'rollup.config.ts'), + 'text', + ); + const variable = await getRollupParameter(context); + + return template(content, variable); + }, + }, + scripts: resolve(TEMPLATES, 'scripts.yaml'), + noSymlinks: ['rollup.config.ts'], + supplementaryConfig: { + gitignore: ['/rollup.config.ts'], + rollup: resolve(CONFIGS, 'rollup.yaml'), + }, + variable: DEFAULT_VARIABLE, + }; +} diff --git a/source/plugin.ts b/source/plugin.ts new file mode 100644 index 0000000..a4b5bf2 --- /dev/null +++ b/source/plugin.ts @@ -0,0 +1,117 @@ +/* + * *** MIT LICENSE *** + * ------------------------------------------------------------------------- + * This code may be modified and distributed under the MIT license. + * See the LICENSE file for details. + * ------------------------------------------------------------------------- + * + * @summary Collection of plugin related helpers + * + * @author Alvis HT Tang + * @license MIT + * @copyright Copyright (c) 2021 - All Rights Reserved. + * ------------------------------------------------------------------------- + */ + +import { isDirective } from 'presetter'; + +import type { ApplyDirective, ImportDirective } from 'presetter'; + +/** full configuration about a plugin */ +export type PluginConfiguration = + | [name: PluginHeader] + | [name: PluginHeader, options: PluginOptions | null]; + +/** specification of a plugin name and its handling direction (e.g. by invoking the function or just simply specify the name) */ +export type PluginHeader = string | ApplyDirective; + +/** options for a plugin */ +export type PluginOptions = + | Record + | ApplyDirective + | ImportDirective; + +/** plugin configuration as an object */ +export type PluginObject = Record; + +/** plugin configuration as an array */ +export type PluginList = PluginListItem[]; + +/** possible types for individual item in a PluginList */ +type PluginListItem = PluginHeader | [name: PluginHeader] | PluginConfiguration; + +/** all possible configuration form for a collection of plugins */ +export type PluginManifest = PluginList | PluginObject; + +/** + * ensure that the given value is a valid PluginManifest + * @param value value to be tested + * @returns nothing if it's a pass + */ +export function assertPluginManifest( + value: unknown, +): asserts value is PluginManifest { + if (typeof value === 'object') { + if (Array.isArray(value)) { + return assertPluginList(value); + } else if (value !== null) { + return assertPluginObject(value as Record); + } + } + + throw new TypeError('plugin manifest is not in a supported format'); +} + +/** + * ensure that the given value is a valid PluginObject + * @param value value to be tested + */ +export function assertPluginObject( + value: Record, +): asserts value is PluginObject { + // all values must be an object + if ( + [...Object.values(value)].some( + (opt) => typeof opt !== 'object' && !isDirective(opt), + ) + ) { + throw new TypeError('all plugin options must be a object'); + } +} + +/** + * ensure that the given value is a valid PluginList + * @param value value to be tested + */ +export function assertPluginList( + value: unknown[], +): asserts value is PluginList { + for (const plugin of value) { + assertPluginListItem(plugin); + } +} + +const PLUGIN_LIST_MAX_ITEMS = 2; + +/** + * ensure that the given value is a valid PluginListItem + * @param value value to be tested + */ +export function assertPluginListItem( + value: unknown, +): asserts value is PluginListItem { + if ( + typeof value !== 'string' && + !( + Array.isArray(value) && + value.length <= PLUGIN_LIST_MAX_ITEMS && + typeof value[0] === 'string' && + (isDirective(value[1]) || + ['undefined', 'object'].includes(typeof value[1])) + ) + ) { + throw new TypeError( + 'a plugin manifest in an array form must be in either one of the following forms: string, [string], [string, object]', + ); + } +} diff --git a/source/rollup.ts b/source/rollup.ts new file mode 100644 index 0000000..dcbaf05 --- /dev/null +++ b/source/rollup.ts @@ -0,0 +1,224 @@ +/* + * *** MIT LICENSE *** + * ------------------------------------------------------------------------- + * This code may be modified and distributed under the MIT license. + * See the LICENSE file for details. + * ------------------------------------------------------------------------- + * + * @summary Collection of helpers for rollup + * + * @author Alvis HT Tang + * @license MIT + * @copyright Copyright (c) 2021 - All Rights Reserved. + * ------------------------------------------------------------------------- + */ + +import { + isDirective, + isJSON, + merge, + resolveDirective, + template, +} from 'presetter'; + +import { assertPluginManifest } from './plugin'; + +import type { + PluginConfiguration, + PluginList, + PluginManifest, + PluginObject, +} from './plugin'; +import type { + ApplyDirective, + ImportDirective, + ResolvedPresetContext, +} from 'presetter'; + + +/** preset configuration for rollup */ +export interface RollupConfig { + [index: string]: unknown | RollupConfig; + /** list of plugin and its options */ + plugins?: PluginManifest | ApplyDirective | ImportDirective; +} + +/** genuine configuration that rollup would take, making sure all plugins are a list */ +interface TrueRollupConfig { + [index: string]: unknown | TrueRollupConfig; + /** list of plugin and its options */ + plugins?: PluginConfiguration[]; +} + +/** transformed configuration for rollup, with all plugins represented by an object */ +interface IntermediateRollupConfig { + [index: string]: unknown | IntermediateRollupConfig; + /** list of plugin and its options */ + plugins?: PluginObject; +} + +/** + * get template parameters for rollup + * @param context context about the build environment + * @returns template parameter related to rollup + */ +export async function getRollupParameter( + context: ResolvedPresetContext, +): Promise> { + const { config, variable } = context.custom; + + const normalisedConfig = template( + normaliseConfig(transformConfig({ ...config.rollup })), + variable, + ); + + return generateRollupParameter(normalisedConfig, context); +} + +/** + * generate template parameters for rollup + * @param config normalised rollup config + * @param context context about the build environment + * @returns template parameter related to rollup + */ +function generateRollupParameter( + config: TrueRollupConfig, + context: ResolvedPresetContext, +): Record<'rollupImport' | 'rollupExport', string> { + const { importMap, stringifiedConfig } = resolveDirective(config, context); + + // generate import statements + const rollupImport = Object.entries(importMap) + .map(([name, resolved]) => `import * as ${resolved} from '${name}';`) + .join('\n'); + + // generate export statements + const rollupExport = `export default ${stringifiedConfig}`; + + return { rollupImport, rollupExport }; +} + +/** + * normalise rollup config with all plugins represented as a list + * @param config transformed config + * @returns config that rollup would take + */ +function normaliseConfig(config: IntermediateRollupConfig): TrueRollupConfig { + return Object.fromEntries( + Object.entries(config).map(([key, value]): [string, unknown] => { + return [ + key, + isDirective(value) ? value : normaliseConfigValue(key, value), + ]; + }), + ); +} + +/** + * try to normalise any nested configuration + * @param key field name + * @param value value of a field + * @returns normalised value + */ +function normaliseConfigValue(key: string, value: unknown): unknown { + switch (key) { + case 'plugins': + return [ + ...Object.entries(value as PluginObject) + .filter(([_, options]) => options !== null) + .map(([plugin, options]) => + [plugin, normaliseConfigValue(plugin, options)].filter( + (element) => element !== undefined, + ), + ), + ]; + default: + return isJSON(value) + ? normaliseConfig(value as IntermediateRollupConfig) + : value; + } +} + +/** + * transform rollup config with plugins represented by an object for better merging + * @param config rollup config in .presetterrc + * @returns transformed config + */ +function transformConfig( + config: Record, +): IntermediateRollupConfig { + return Object.fromEntries( + Object.entries(config).map(([key, value]): [string, unknown] => { + return [ + key, + isDirective(value) ? value : transformConfigValue(key, value), + ]; + }), + ); +} + +/** + * try to transform any nested configuration + * @param key field name + * @param value value of a field + * @returns transformed value + */ +function transformConfigValue(key: string, value: unknown): unknown { + switch (key) { + case 'plugins': + assertPluginManifest(value); + + return objectifyPlugins(value); + + default: + return isJSON(value) ? transformConfig(value) : value; + } +} + +/** + * objectify rollup plugins + * @param plugins rollup plugin config + * @returns normalised plugin config + */ +function objectifyPlugins( + plugins: PluginManifest, +): IntermediateRollupConfig['plugins'] { + const normalisedPlugin: PluginObject = {}; + + const pluginList: PluginConfiguration[] = Array.isArray(plugins) + ? arrayToPluginConfiguration(plugins) + : objectToPluginConfiguration(plugins); + + for (const [name, options] of pluginList) { + Object.assign( + normalisedPlugin, + merge(normalisedPlugin, { [name]: options }), + ); + } + + return normalisedPlugin; +} + +/** + * normalise rollup plugin config in array form + * @param plugins rollup plugin config in array form + * @returns normalised plugin config + */ +function arrayToPluginConfiguration( + plugins: PluginList, +): PluginConfiguration[] { + return plugins.map((plugin) => + typeof plugin === 'string' ? [plugin] : plugin, + ); +} + +/** + * normalise rollup plugin config in object form + * @param plugins rollup plugin config in object form + * @returns normalised plugin config + */ +function objectToPluginConfiguration( + plugins: PluginObject, +): PluginConfiguration[] { + return [...Object.entries(plugins)]; +} diff --git a/spec/index.spec.ts b/spec/index.spec.ts new file mode 100644 index 0000000..e216991 --- /dev/null +++ b/spec/index.spec.ts @@ -0,0 +1,52 @@ +/* + * *** MIT LICENSE *** + * ------------------------------------------------------------------------- + * This code may be modified and distributed under the MIT license. + * See the LICENSE file for details. + * ------------------------------------------------------------------------- + * + * @summary Tests on config generation + * + * @author Alvis HT Tang + * @license MIT + * @copyright Copyright (c) 2020 - All Rights Reserved. + * ------------------------------------------------------------------------- + */ + +import { readdirSync } from 'fs'; +import { resolve } from 'path'; +import { resolveContext, resolveDynamicMap } from 'presetter'; + +import getPresetAsset from '#index'; + +jest.mock('path', () => ({ + __esModule: true, + ...jest.requireActual('path'), + resolve: jest.fn(jest.requireActual('path').resolve), +})); + +describe('fn:getPresetAsset', () => { + it('use all templates', async () => { + const assets = [await getPresetAsset()]; + const context = await resolveContext(assets, { + target: { name: 'preset', root: '/', package: {} }, + custom: { preset: 'preset' }, + }); + + // load all potential dynamic content + await resolveDynamicMap(assets, context, 'supplementaryConfig'); + await resolveDynamicMap(assets, context, 'template'); + + const TEMPLATES = resolve(__dirname, '..', 'templates'); + const allTemplates = await readdirSync(TEMPLATES); + const CONFIGS = resolve(__dirname, '..', 'configs'); + const supplementaryConfig = await readdirSync(CONFIGS); + + for (const path of allTemplates) { + expect(resolve).toBeCalledWith(TEMPLATES, path); + } + for (const path of supplementaryConfig) { + expect(resolve).toBeCalledWith(CONFIGS, path); + } + }); +}); diff --git a/spec/plugin.spec.ts b/spec/plugin.spec.ts new file mode 100644 index 0000000..b95d3e3 --- /dev/null +++ b/spec/plugin.spec.ts @@ -0,0 +1,101 @@ +/* + * *** MIT LICENSE *** + * ------------------------------------------------------------------------- + * This code may be modified and distributed under the MIT license. + * See the LICENSE file for details. + * ------------------------------------------------------------------------- + * + * @summary Tests on plugin related helpers + * + * @author Alvis HT Tang + * @license MIT + * @copyright Copyright (c) 2021 - All Rights Reserved. + * ------------------------------------------------------------------------- + */ + +import { + assertPluginList, + assertPluginListItem, + assertPluginObject, + assertPluginManifest, +} from '#plugin'; + +describe('fn:assertPluginListItem', () => { + it('pass with just a string', () => { + expect(() => assertPluginListItem('plugin')).not.toThrow(); + }); + + it('pass with a string in an array', () => { + expect(() => assertPluginListItem(['plugin'])).not.toThrow(); + }); + + it('pass with a string and its options in an array', () => { + expect(() => + assertPluginListItem(['plugin', { options: true }]), + ).not.toThrow(); + }); + + it('fails with a non-string header', () => { + expect(() => assertPluginListItem([0])).toThrow(TypeError); + }); + + it('fails with an array more than 2 items', () => { + expect(() => + assertPluginListItem(['plugin', { options: true }, 'extra']), + ).toThrow(TypeError); + }); +}); + +describe('fn:assertPluginList', () => { + it('pass with a valid plugin configuration list', () => { + expect(() => + assertPluginList(['plugin', ['plugin'], ['plugin', { options: true }]]), + ).not.toThrow(); + }); + + it('fail with any invalid plugin configurations', () => { + expect(() => + assertPluginList([ + 'plugin', + ['plugin'], + ['plugin', { options: true }], + { invalid: true }, + ]), + ).toThrow(TypeError); + }); +}); + +describe('fn:assertPluginObject', () => { + it('pass with a valid plugin configuration object', () => { + expect(() => + assertPluginObject({ plugin: { options: true } }), + ).not.toThrow(); + }); + + it('fail with any invalid plugin options', () => { + expect(() => assertPluginObject({ plugin: true })).toThrow(TypeError); + }); +}); + +describe('fn:assertPluginManifest', () => { + it('pass with a valid plugin configuration object', () => { + expect(() => + assertPluginManifest({ plugin: { options: true } }), + ).not.toThrow(); + }); + + it('pass with a valid plugin configuration list', () => { + expect(() => + assertPluginManifest([ + 'plugin', + ['plugin'], + ['plugin', { options: true }], + ]), + ).not.toThrow(); + }); + + it('fail with any invalid manifest', () => { + expect(() => assertPluginManifest(null)).toThrow(TypeError); + expect(() => assertPluginManifest('invalid')).toThrow(TypeError); + }); +}); diff --git a/spec/rollup.spec.ts b/spec/rollup.spec.ts new file mode 100644 index 0000000..fbddf67 --- /dev/null +++ b/spec/rollup.spec.ts @@ -0,0 +1,220 @@ +/* + * *** MIT LICENSE *** + * ------------------------------------------------------------------------- + * This code may be modified and distributed under the MIT license. + * See the LICENSE file for details. + * ------------------------------------------------------------------------- + * + * @summary Tests on the helpers for rollup + * + * @author Alvis HT Tang + * @license MIT + * @copyright Copyright (c) 2021 - All Rights Reserved. + * ------------------------------------------------------------------------- + */ + +import { getRollupParameter } from '#rollup'; + +import type { Config, ResolvedPresetContext } from 'presetter'; + +describe('fn:getRollupParameter', () => { + const generateContext = (config?: Config): ResolvedPresetContext => ({ + target: { name: 'target', root: '/path/to/target', package: {} }, + custom: { + preset: 'preset', + config: config ? { rollup: config } : {}, + noSymlinks: [], + variable: {}, + }, + }); + + it('add plugins by importing from another config files', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: '@import config[plugins]', + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'config';`, + rollupExport: 'export default {"plugins": import0.plugins}', + }); + }); + + it('add a plugin by adding the plugin in the object form, using the supplied options', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: { '@apply newPlugin': { name: 'newPlugin' } }, + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'newPlugin';`, + rollupExport: + 'export default {"plugins": [import0(...[{"name": "newPlugin"}])]}', + }); + }); + + it('add a plugin by just the plugin name, using everything default', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: ['@apply newPlugin'], + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'newPlugin';`, + rollupExport: 'export default {"plugins": [import0(...[])]}', + }); + }); + + it('add a plugin by adding the plugin in the array form, using everything default', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: [['@apply newPlugin']], + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'newPlugin';`, + rollupExport: 'export default {"plugins": [import0(...[])]}', + }); + }); + + it('add a plugin by adding the plugin in the array form, using the supplied options', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: [['@apply newPlugin', { name: 'newPlugin' }]], + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'newPlugin';`, + rollupExport: + 'export default {"plugins": [import0(...[{"name": "newPlugin"}])]}', + }); + }); + + it('remove a plugin by setting the plugin config as null', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: { + '@apply pluginWithOptions': null, + }, + }), + ), + ).toEqual({ + rollupImport: ``, + rollupExport: 'export default {"plugins": []}', + }); + }); + + it('add a plugin from a named import', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: { + '@apply pluginWithOptions': null, + '@apply pluginWithoutOptions': null, + '@apply newPlugin[plugin]': { options: true }, + }, + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'newPlugin';`, + rollupExport: + 'export default {"plugins": [import0.plugin(...[{"options": true}])]}', + }); + }); + + it('generate default parameters if no further config is given', async () => { + expect(await getRollupParameter(generateContext())).toEqual({ + rollupImport: ``, + rollupExport: 'export default {}', + }); + }); + + it('generate config with extra options other than plugins', async () => { + expect( + await getRollupParameter( + generateContext({ + cache: null, + extra: { options: true }, + external: ['import1', 'import2'], + }), + ), + ).toEqual({ + rollupImport: ``, + rollupExport: + 'export default {"cache": null, "extra": {"options": true}, "external": ["import1", "import2"]}', + }); + }); + + it('generate extra import statements for imports within plugin options', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: { + '@apply pluginWithOptions': '@import another', + '@apply pluginWithoutOptions': '@import another', + }, + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'pluginWithOptions';\nimport * as import2 from 'pluginWithoutOptions';`, + rollupExport: `export default {"plugins": [import1(...[import0]), import2(...[import0])]}`, + }); + + expect( + await getRollupParameter( + generateContext({ + plugins: [ + ['@apply pluginWithOptions', '@import another'], + ['@apply pluginWithoutOptions', '@import another'], + ], + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'pluginWithOptions';\nimport * as import2 from 'pluginWithoutOptions';`, + rollupExport: `export default {"plugins": [import1(...[import0]), import2(...[import0])]}`, + }); + }); + + it('generate only one import statement per unique import', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: { + '@apply pluginWithOptions': null, + '@apply pluginWithoutOptions': null, + '@apply plugin0': '@import another[export0]', + '@apply plugin1': '@import another[export1]', + }, + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'plugin0';\nimport * as import2 from 'plugin1';`, + rollupExport: `export default {"plugins": [import1(...[import0.export0]), import2(...[import0.export1])]}`, + }); + }); + + it('support nested plugin declaration', async () => { + expect( + await getRollupParameter( + generateContext({ + plugins: { + '@apply pluginWithOptions': null, + '@apply pluginWithoutOptions': null, + '@apply plugin0': { + plugins: { another: '@import options[export0]' }, + }, + }, + }), + ), + ).toEqual({ + rollupImport: `import * as import0 from 'options';\nimport * as import1 from 'plugin0';`, + rollupExport: `export default {"plugins": [import1(...[{"plugins": [["another", import0.export0]]}])]}`, + }); + }); +}); diff --git a/templates/rollup.config.ts b/templates/rollup.config.ts new file mode 100644 index 0000000..dc2365f --- /dev/null +++ b/templates/rollup.config.ts @@ -0,0 +1,3 @@ +{rollupImport} + +{rollupExport} \ No newline at end of file diff --git a/templates/scripts.yaml b/templates/scripts.yaml new file mode 100644 index 0000000..8f5b630 --- /dev/null +++ b/templates/scripts.yaml @@ -0,0 +1,5 @@ +# replace the `prepare` template from presetter-preset +# so that the build procedure will not be triggered upon package installation +build: run-s clean build:rollup +build:rollup: cross-env NODE_ENV=production rollup --config rollup.config.ts --configPlugin rollup-plugin-ts +develop: run-s "build:rollup -- --watch {@}" -- From 7f3e8e6870606ce2e9c63189844e36b36c77d16e Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 30 Sep 2021 18:37:31 +0100 Subject: [PATCH 02/40] refactor: rename presetter-preset to presetter-preset-essentials --- .presetterrc.json | 2 +- README.md | 8 ++++---- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.presetterrc.json b/.presetterrc.json index e33a3fe..29c6753 100644 --- a/.presetterrc.json +++ b/.presetterrc.json @@ -1,5 +1,5 @@ { - "preset": "presetter-preset", + "preset": "presetter-preset-essentials", "config": { "npmignore": ["!/configs/**", "!/templates/**"] }, diff --git a/README.md b/README.md index 98c731d..ecc4613 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ [**FULL DOCUMENTATION IS AVAILABLE HERE**](https://github.com/alvis/presetter/blob/master/README.md) -1. Bootstrap your project with `presetter-preset` & `presetter-preset-rollup` +1. Bootstrap your project with `presetter-preset-essentials` & `presetter-preset-rollup` ```shell npx presetter use presetter-preset presetter-preset-rollup @@ -72,7 +72,7 @@ For NodeJS to import the correct export, remember to specify the following in yo ## Project Structure -After installing `presetter-preset` & `presetter-preset-rollup`, your project file structure should look like the following or with more configuration file if you also installed `presetter-preset`. +After installation, your project file structure should resemble the following or with more configuration files if you also installed other presets such as [`presetter-preset-essentials`](https://github.com/alvis/presetter/blob/master/packages/preset-essentials). Implement your business logic under `source` and prepare tests under `spec`. @@ -104,11 +104,11 @@ The structure of `.presetterrc` should follow the interface below: ```ts interface PresetterRC { - /** name(s) of the preset e.g. presetter-preset */ + /** name(s) of the preset e.g. presetter-preset-rollup */ name: string | string[]; /** additional configuration passed to the preset for generating the configuration files */ config?: { - // ┌─ configuration for other tools via other presets (e.g. presetter-preset) + // ┌─ configuration for other tools via other presets (e.g. presetter-preset-essentials) // ... /** additional configuration for rollup */ diff --git a/package.json b/package.json index 2bfafed..205ee1d 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,6 @@ }, "devDependencies": { "presetter": "file:../presetter", - "presetter-preset": "file:../preset" + "presetter-preset-essentials": "file:../preset-essentials" } } From dd9f27c09f626a5c3e54675381ef6ba5ef850fc8 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 30 Sep 2021 21:04:39 +0100 Subject: [PATCH 03/40] build: use presetter-preset-strict wherever possible --- .presetterrc.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.presetterrc.json b/.presetterrc.json index 29c6753..538771f 100644 --- a/.presetterrc.json +++ b/.presetterrc.json @@ -1,5 +1,5 @@ { - "preset": "presetter-preset-essentials", + "preset": "presetter-preset-strict", "config": { "npmignore": ["!/configs/**", "!/templates/**"] }, diff --git a/package.json b/package.json index 205ee1d..57b5a70 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,6 @@ }, "devDependencies": { "presetter": "file:../presetter", - "presetter-preset-essentials": "file:../preset-essentials" + "presetter-preset-strict": "file:../preset-strict" } } From daf36df63e4b4462abf2678f13ac145bf1a65c99 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Mon, 4 Oct 2021 07:43:29 +0100 Subject: [PATCH 04/40] fix(presetter): narrow types in directive's argument --- spec/rollup.spec.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/rollup.spec.ts b/spec/rollup.spec.ts index fbddf67..44c5c9c 100644 --- a/spec/rollup.spec.ts +++ b/spec/rollup.spec.ts @@ -51,7 +51,7 @@ describe('fn:getRollupParameter', () => { ).toEqual({ rollupImport: `import * as import0 from 'newPlugin';`, rollupExport: - 'export default {"plugins": [import0(...[{"name": "newPlugin"}])]}', + 'export default {"plugins": [import0(...([{"name": "newPlugin"}] as const))]}', }); }); @@ -64,7 +64,7 @@ describe('fn:getRollupParameter', () => { ), ).toEqual({ rollupImport: `import * as import0 from 'newPlugin';`, - rollupExport: 'export default {"plugins": [import0(...[])]}', + rollupExport: 'export default {"plugins": [import0(...([] as const))]}', }); }); @@ -77,7 +77,7 @@ describe('fn:getRollupParameter', () => { ), ).toEqual({ rollupImport: `import * as import0 from 'newPlugin';`, - rollupExport: 'export default {"plugins": [import0(...[])]}', + rollupExport: 'export default {"plugins": [import0(...([] as const))]}', }); }); @@ -91,7 +91,7 @@ describe('fn:getRollupParameter', () => { ).toEqual({ rollupImport: `import * as import0 from 'newPlugin';`, rollupExport: - 'export default {"plugins": [import0(...[{"name": "newPlugin"}])]}', + 'export default {"plugins": [import0(...([{"name": "newPlugin"}] as const))]}', }); }); @@ -124,7 +124,7 @@ describe('fn:getRollupParameter', () => { ).toEqual({ rollupImport: `import * as import0 from 'newPlugin';`, rollupExport: - 'export default {"plugins": [import0.plugin(...[{"options": true}])]}', + 'export default {"plugins": [import0.plugin(...([{"options": true}] as const))]}', }); }); @@ -163,7 +163,7 @@ describe('fn:getRollupParameter', () => { ), ).toEqual({ rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'pluginWithOptions';\nimport * as import2 from 'pluginWithoutOptions';`, - rollupExport: `export default {"plugins": [import1(...[import0]), import2(...[import0])]}`, + rollupExport: `export default {"plugins": [import1(...([import0] as const)), import2(...([import0] as const))]}`, }); expect( @@ -177,7 +177,7 @@ describe('fn:getRollupParameter', () => { ), ).toEqual({ rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'pluginWithOptions';\nimport * as import2 from 'pluginWithoutOptions';`, - rollupExport: `export default {"plugins": [import1(...[import0]), import2(...[import0])]}`, + rollupExport: `export default {"plugins": [import1(...([import0] as const)), import2(...([import0] as const))]}`, }); }); @@ -195,7 +195,7 @@ describe('fn:getRollupParameter', () => { ), ).toEqual({ rollupImport: `import * as import0 from 'another';\nimport * as import1 from 'plugin0';\nimport * as import2 from 'plugin1';`, - rollupExport: `export default {"plugins": [import1(...[import0.export0]), import2(...[import0.export1])]}`, + rollupExport: `export default {"plugins": [import1(...([import0.export0] as const)), import2(...([import0.export1] as const))]}`, }); }); @@ -214,7 +214,7 @@ describe('fn:getRollupParameter', () => { ), ).toEqual({ rollupImport: `import * as import0 from 'options';\nimport * as import1 from 'plugin0';`, - rollupExport: `export default {"plugins": [import1(...[{"plugins": [["another", import0.export0]]}])]}`, + rollupExport: `export default {"plugins": [import1(...([{"plugins": [["another", import0.export0]]}] as const))]}`, }); }); }); From e78ce2684bfa61018e1cf72686aab778d0af44be Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Mon, 4 Oct 2021 14:13:53 +0100 Subject: [PATCH 05/40] chore(release): publish v3.0.0 --- CHANGELOG.md | 25 +++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..90f48a2 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,25 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +# [3.0.0](https://github.com/alvis/presetter/compare/v2.1.0...v3.0.0) (2021-10-04) + + +### ✨ Features + +* **preset-rollup:** provide a preset for code bundling via rollup ([b0704b0](https://github.com/alvis/presetter/commit/b0704b0fe727c2724d7057d3803ecee49c230eff)) + + +### 🐛 Bug Fixes + +* **presetter:** narrow types in directive's argument ([c6de804](https://github.com/alvis/presetter/commit/c6de8044d4d9f584e3ef4ef688f81c08db425d1c)) + + +### 🛠 Builds + +* use presetter-preset-strict wherever possible ([4ff72a1](https://github.com/alvis/presetter/commit/4ff72a1a9730dfd4ad99d0a63dd4b005041ce759)) + + +### 📦 Code Refactoring + +* rename presetter-preset to presetter-preset-essentials ([b799587](https://github.com/alvis/presetter/commit/b7995871d85a1ccb8d2e43ba9b3a7e305de7a99b)) diff --git a/package.json b/package.json index 57b5a70..4b56df8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "0.0.0", + "version": "3.0.0", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", From 45d6ec3666e45af18205be83f0236a57e6e42e1e Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 14 Oct 2021 09:20:40 +0100 Subject: [PATCH 06/40] chore(release): publish v3.0.1 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90f48a2..66d3c8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.0.1](https://github.com/alvis/presetter/compare/v3.0.0...v3.0.1) (2021-10-14) + + + # [3.0.0](https://github.com/alvis/presetter/compare/v2.1.0...v3.0.0) (2021-10-04) diff --git a/package.json b/package.json index 4b56df8..727717b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.0.0", + "version": "3.0.1", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.0.0", + "presetter": "^3.0.1", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From a2496b38273d5db4c6c3cec37ee3473644919948 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 3 Nov 2021 08:46:42 +0000 Subject: [PATCH 07/40] chore(release): publish v3.0.2 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66d3c8d..cbeeb6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.0.2](https://github.com/alvis/presetter/compare/v3.0.1...v3.0.2) (2021-11-03) + + + ## [3.0.1](https://github.com/alvis/presetter/compare/v3.0.0...v3.0.1) (2021-10-14) diff --git a/package.json b/package.json index 727717b..6469043 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.0.1", + "version": "3.0.2", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.0.1", + "presetter": "^3.0.2", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From d2a2ecc746bd892cfeaaecf1e10b1c0dc09243b9 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 3 Nov 2021 09:41:58 +0000 Subject: [PATCH 08/40] chore(release): publish v3.0.3 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbeeb6e..4956c78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.0.3](https://github.com/alvis/presetter/compare/v3.0.2...v3.0.3) (2021-11-03) + + + ## [3.0.2](https://github.com/alvis/presetter/compare/v3.0.1...v3.0.2) (2021-11-03) diff --git a/package.json b/package.json index 6469043..6e4f918 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.0.2", + "version": "3.0.3", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.0.2", + "presetter": "^3.0.3", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From 5fb8c2c564a4c0f955842f0db628e235bec5dd21 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Tue, 28 Dec 2021 18:44:37 +0000 Subject: [PATCH 09/40] chore(release): publish v3.1.0 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4956c78..c78a65c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +# [3.1.0](https://github.com/alvis/presetter/compare/v3.0.3...v3.1.0) (2021-12-28) + + + ## [3.0.3](https://github.com/alvis/presetter/compare/v3.0.2...v3.0.3) (2021-11-03) diff --git a/package.json b/package.json index 6e4f918..87fa982 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.0.3", + "version": "3.1.0", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.0.3", + "presetter": "^3.1.0", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From 7904e74115300993f0ef8199a4662ab79587de79 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 29 Dec 2021 10:24:43 +0000 Subject: [PATCH 10/40] chore(release): publish v3.1.1 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c78a65c..642b5b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.1.1](https://github.com/alvis/presetter/compare/v3.1.0...v3.1.1) (2021-12-29) + + + # [3.1.0](https://github.com/alvis/presetter/compare/v3.0.3...v3.1.0) (2021-12-28) diff --git a/package.json b/package.json index 87fa982..e3e4f9b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.1.0", + "version": "3.1.1", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.1.0", + "presetter": "^3.1.1", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From bfd08357a2b8104d3f981b3fd8a50e32185930fb Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sat, 14 May 2022 11:07:01 +0100 Subject: [PATCH 11/40] chore: update package dependencies --- source/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index 65723b7..f51cd43 100644 --- a/source/index.ts +++ b/source/index.ts @@ -18,9 +18,8 @@ import { loadFile, template } from 'presetter'; import { getRollupParameter } from './rollup'; -import type { PresetAsset } from 'presetter'; - import type { RollupConfig } from './rollup'; +import type { PresetAsset } from 'presetter'; // paths to the template directory const TEMPLATES = resolve(__dirname, '..', 'templates'); @@ -51,6 +50,7 @@ export const DEFAULT_VARIABLE: Variable = { export default async function (): Promise { return { template: { + /* eslint-disable @typescript-eslint/naming-convention */ 'rollup.config.ts': async (context) => { const content = await loadFile( resolve(TEMPLATES, 'rollup.config.ts'), @@ -59,6 +59,7 @@ export default async function (): Promise { const variable = await getRollupParameter(context); return template(content, variable); + /* eslint-enable @typescript-eslint/naming-convention */ }, }, scripts: resolve(TEMPLATES, 'scripts.yaml'), From 3c7d318f060a7411fb71cb9234ee9336c2e8d3e3 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sun, 15 May 2022 16:07:02 +0100 Subject: [PATCH 12/40] refactor: use American English --- README.md | 12 ++++++------ source/rollup.ts | 43 +++++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index ecc4613..d3431ab 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ 🏄🏻 _A collection of opinionated configurations for a building a code bundle via rollup for presetter_ -•   [Quick Start](#quick-start)   •   [Project Structure](#project-structure)   •   [Customisation](#customisation)   •   [Scripts](#script-template-summary)   • +•   [Quick Start](#quick-start)   •   [Project Structure](#project-structure)   •   [Customization](#customization)   •   [Scripts](#script-template-summary)   • [![npm](https://img.shields.io/npm/v/presetter-preset-rollup?style=flat-square)](https://github.com/alvis/presetter/releases) [![build](https://img.shields.io/github/workflow/status/alvis/presetter/code%20test?style=flat-square)](https://github.com/alvis/presetter/actions) @@ -76,12 +76,12 @@ After installation, your project file structure should resemble the following or Implement your business logic under `source` and prepare tests under `spec`. -**TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `.presetterrc.json`. See the [customisation](https://github.com/alvis/presetter/blob/master/packages/preset-rollup#customisation) section below for more details. +**TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `.presetterrc.json`. See the [customization](https://github.com/alvis/presetter/blob/master/packages/preset-rollup#customization) section below for more details. ``` (root) ├─ .git - ├─ .preseterrc.json + ├─ .presetterrc.json ├─ node_modules ├─ source │ ├─ @@ -93,10 +93,10 @@ Implement your business logic under `source` and prepare tests under `spec`. └─ rollup.config.ts ``` -## Customisation +## Customization By default, this preset exports a handy configuration for rollup for a typescript project. -But you can further customise (either extending or replacing) the configuration by specifying the change in the config file (`.presetterrc` or `.presetterrc.json`). +But you can further customize (either extending or replacing) the configuration by specifying the change in the config file (`.presetterrc` or `.presetterrc.json`). These settings are available in the `config` field in the config file. For directories, the setting is specified in the `variable` field. @@ -118,7 +118,7 @@ interface PresetterRC { /** list of plugin and its options */ plugins?: - | NormalisedRollupConfig['plugins'] + | NormalizedRollupConfig['plugins'] | Array< | string | [name: string] diff --git a/source/rollup.ts b/source/rollup.ts index dcbaf05..f5e9074 100644 --- a/source/rollup.ts +++ b/source/rollup.ts @@ -35,7 +35,6 @@ import type { ResolvedPresetContext, } from 'presetter'; - /** preset configuration for rollup */ export interface RollupConfig { [index: string]: unknown | RollupConfig; @@ -67,17 +66,17 @@ export async function getRollupParameter( ): Promise> { const { config, variable } = context.custom; - const normalisedConfig = template( - normaliseConfig(transformConfig({ ...config.rollup })), + const normalizedConfig = template( + normalizeConfig(transformConfig({ ...config.rollup })), variable, ); - return generateRollupParameter(normalisedConfig, context); + return generateRollupParameter(normalizedConfig, context); } /** * generate template parameters for rollup - * @param config normalised rollup config + * @param config normalized rollup config * @param context context about the build environment * @returns template parameter related to rollup */ @@ -99,42 +98,42 @@ function generateRollupParameter( } /** - * normalise rollup config with all plugins represented as a list + * normalize rollup config with all plugins represented as a list * @param config transformed config * @returns config that rollup would take */ -function normaliseConfig(config: IntermediateRollupConfig): TrueRollupConfig { +function normalizeConfig(config: IntermediateRollupConfig): TrueRollupConfig { return Object.fromEntries( Object.entries(config).map(([key, value]): [string, unknown] => { return [ key, - isDirective(value) ? value : normaliseConfigValue(key, value), + isDirective(value) ? value : normalizeConfigValue(key, value), ]; }), ); } /** - * try to normalise any nested configuration + * try to normalize any nested configuration * @param key field name * @param value value of a field - * @returns normalised value + * @returns normalized value */ -function normaliseConfigValue(key: string, value: unknown): unknown { +function normalizeConfigValue(key: string, value: unknown): unknown { switch (key) { case 'plugins': return [ ...Object.entries(value as PluginObject) .filter(([_, options]) => options !== null) .map(([plugin, options]) => - [plugin, normaliseConfigValue(plugin, options)].filter( + [plugin, normalizeConfigValue(plugin, options)].filter( (element) => element !== undefined, ), ), ]; default: return isJSON(value) - ? normaliseConfig(value as IntermediateRollupConfig) + ? normalizeConfig(value as IntermediateRollupConfig) : value; } } @@ -178,12 +177,12 @@ function transformConfigValue(key: string, value: unknown): unknown { /** * objectify rollup plugins * @param plugins rollup plugin config - * @returns normalised plugin config + * @returns normalized plugin config */ function objectifyPlugins( plugins: PluginManifest, ): IntermediateRollupConfig['plugins'] { - const normalisedPlugin: PluginObject = {}; + const normalizedPlugin: PluginObject = {}; const pluginList: PluginConfiguration[] = Array.isArray(plugins) ? arrayToPluginConfiguration(plugins) @@ -191,18 +190,18 @@ function objectifyPlugins( for (const [name, options] of pluginList) { Object.assign( - normalisedPlugin, - merge(normalisedPlugin, { [name]: options }), + normalizedPlugin, + merge(normalizedPlugin, { [name]: options }), ); } - return normalisedPlugin; + return normalizedPlugin; } /** - * normalise rollup plugin config in array form + * normalize rollup plugin config in array form * @param plugins rollup plugin config in array form - * @returns normalised plugin config + * @returns normalized plugin config */ function arrayToPluginConfiguration( plugins: PluginList, @@ -213,9 +212,9 @@ function arrayToPluginConfiguration( } /** - * normalise rollup plugin config in object form + * normalize rollup plugin config in object form * @param plugins rollup plugin config in object form - * @returns normalised plugin config + * @returns normalized plugin config */ function objectToPluginConfiguration( plugins: PluginObject, From 7ea9b1bcee12df8e2b47002d322378c8dc7a59f9 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 18 May 2022 15:15:41 +0100 Subject: [PATCH 13/40] chore(release): publish v3.2.0 --- CHANGELOG.md | 14 ++++++++++++++ package.json | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 642b5b7..a5bfc19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +# [3.2.0](https://github.com/alvis/presetter/compare/v3.1.1...v3.2.0) (2022-05-18) + + +### 📦 Code Refactoring + +* use American English ([17315b7](https://github.com/alvis/presetter/commit/17315b78a9d65fb6193a609dd27b4d34454df1bc)) + + +### ♻️ Chores + +* update package dependencies ([4e50e0d](https://github.com/alvis/presetter/commit/4e50e0d2fce1bea470fbea62fc1eba52dccb3aed)) + + + ## [3.1.1](https://github.com/alvis/presetter/compare/v3.1.0...v3.1.1) (2021-12-29) diff --git a/package.json b/package.json index e3e4f9b..bc7e740 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.1.1", + "version": "3.2.0", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.1.1", + "presetter": "^3.2.0", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From 08c9487eed75c5436c28a015e2ae54e07411f35b Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 8 Jul 2022 12:20:50 +0100 Subject: [PATCH 14/40] docs: update dependencies badges --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3431ab..68d2912 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [![maintainability](https://img.shields.io/codeclimate/maintainability/alvis/presetter?style=flat-square)](https://codeclimate.com/github/alvis/presetter/maintainability) [![coverage](https://img.shields.io/codeclimate/coverage/alvis/presetter?style=flat-square)](https://codeclimate.com/github/alvis/presetter/test_coverage) [![security](https://img.shields.io/snyk/vulnerabilities/github/alvis/presetter/packages/preset-rollup/package.json.svg?style=flat-square)](https://snyk.io/test/github/alvis/presetter?targetFile=packages/preset-rollup/package.json&style=flat-square) -[![dependencies](https://img.shields.io/david/alvis/presetter?path=packages/preset-rollup&style=flat-square)](https://david-dm.org/alvis/presetter?path=packages/preset-rollup) +[![dependencies](https://img.shields.io/librariesio/release/npm/presetter-preset-rollup?style=flat-square)](https://libraries.io/npm/presetter-preset-rollup) [![license](https://img.shields.io/github/license/alvis/presetter.svg?style=flat-square)](https://github.com/alvis/presetter/blob/master/LICENSE) From 530399e182ec16614dc919b1245799e44e4251fe Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Tue, 12 Jul 2022 12:54:01 +0100 Subject: [PATCH 15/40] chore(release): publish v3.3.0 --- CHANGELOG.md | 9 +++++++++ package.json | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5bfc19..b7ffc92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +# [3.3.0](https://github.com/alvis/presetter/compare/v3.2.0...v3.3.0) (2022-07-12) + + +### 📚 Documentation + +* update dependencies badges ([94c084d](https://github.com/alvis/presetter/commit/94c084ddc39821106c9077bd4c12d1a7da9529eb)) + + + # [3.2.0](https://github.com/alvis/presetter/compare/v3.1.1...v3.2.0) (2022-05-18) diff --git a/package.json b/package.json index bc7e740..b8a6749 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.2.0", + "version": "3.3.0", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.2.0", + "presetter": "^3.3.0", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From f3c1738abb53f18dcefb75390113205d2d318c73 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 14 Jul 2022 22:55:47 +0100 Subject: [PATCH 16/40] fix(presetter): resolve presets as a tree not a list --- spec/index.spec.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/spec/index.spec.ts b/spec/index.spec.ts index e216991..2c4ef62 100644 --- a/spec/index.spec.ts +++ b/spec/index.spec.ts @@ -15,7 +15,7 @@ import { readdirSync } from 'fs'; import { resolve } from 'path'; -import { resolveContext, resolveDynamicMap } from 'presetter'; +import { loadDynamicMap, resolveContext } from 'presetter'; import getPresetAsset from '#index'; @@ -27,15 +27,18 @@ jest.mock('path', () => ({ describe('fn:getPresetAsset', () => { it('use all templates', async () => { - const assets = [await getPresetAsset()]; - const context = await resolveContext(assets, { - target: { name: 'preset', root: '/', package: {} }, - custom: { preset: 'preset' }, + const asset = await getPresetAsset(); + const context = await resolveContext({ + graph: [{ name: 'preset', asset, nodes: [] }], + context: { + target: { name: 'preset', root: '/', package: {} }, + custom: { preset: 'preset' }, + }, }); // load all potential dynamic content - await resolveDynamicMap(assets, context, 'supplementaryConfig'); - await resolveDynamicMap(assets, context, 'template'); + await loadDynamicMap(asset.supplementaryConfig, context); + await loadDynamicMap(asset.template, context); const TEMPLATES = resolve(__dirname, '..', 'templates'); const allTemplates = await readdirSync(TEMPLATES); From bc8037d29037bea7fc0af0e8bc0e9a762b643979 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Tue, 2 Aug 2022 19:19:41 +0100 Subject: [PATCH 17/40] chore(release): publish v3.4.0 --- CHANGELOG.md | 9 +++++++++ package.json | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ffc92..b224c1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +# [3.4.0](https://github.com/alvis/presetter/compare/v3.3.0...v3.4.0) (2022-08-02) + + +### 🐛 Bug Fixes + +* **presetter:** resolve presets as a tree not a list ([0db5ff3](https://github.com/alvis/presetter/commit/0db5ff3b0020735591b3986c216578857dde3039)) + + + # [3.3.0](https://github.com/alvis/presetter/compare/v3.2.0...v3.3.0) (2022-07-12) diff --git a/package.json b/package.json index b8a6749..61c5c0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.3.0", + "version": "3.4.0", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.3.0", + "presetter": "^3.4.0", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^1.0.0", From cb5384bbd34cf789f03e800f10c3ce457570189b Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 3 Aug 2022 06:12:02 +0100 Subject: [PATCH 18/40] fix: update packages --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 61c5c0a..aa1eeec 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "watch": "run watch" }, "peerDependencies": { - "@rollup/plugin-commonjs": "^20.0.0", + "@rollup/plugin-commonjs": "^22.0.0", "@rollup/plugin-graphql": "^1.0.0", "@rollup/plugin-image": "^2.0.0", "@rollup/plugin-json": "^4.0.0", @@ -42,7 +42,7 @@ "presetter": "^3.4.0", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", - "rollup-plugin-ts": "^1.0.0", + "rollup-plugin-ts": "^3.0.0", "rollup-plugin-tsconfig-paths": "^1.0.0", "rollup-plugin-visualizer": "^5.0.0" }, From cf8be54e886b195bd14eb771e38c5a1b3f92280c Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Mon, 8 Aug 2022 21:07:44 +0100 Subject: [PATCH 19/40] fix(presetter): merge arrays only if the values are all primitive --- package.json | 3 ++- source/plugin.ts | 6 ++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index aa1eeec..d42945c 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ }, "devDependencies": { "presetter": "file:../presetter", - "presetter-preset-strict": "file:../preset-strict" + "presetter-preset-strict": "file:../preset-strict", + "type-fest": "^2.0.0" } } diff --git a/source/plugin.ts b/source/plugin.ts index a4b5bf2..9613232 100644 --- a/source/plugin.ts +++ b/source/plugin.ts @@ -16,6 +16,7 @@ import { isDirective } from 'presetter'; import type { ApplyDirective, ImportDirective } from 'presetter'; +import type { JsonObject } from 'type-fest'; /** full configuration about a plugin */ export type PluginConfiguration = @@ -26,10 +27,7 @@ export type PluginConfiguration = export type PluginHeader = string | ApplyDirective; /** options for a plugin */ -export type PluginOptions = - | Record - | ApplyDirective - | ImportDirective; +export type PluginOptions = JsonObject | ApplyDirective | ImportDirective; /** plugin configuration as an object */ export type PluginObject = Record; From aae318098d766b02f0bc68b252ba4f847bdee035 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 10 Aug 2022 14:07:13 +0100 Subject: [PATCH 20/40] chore(release): publish v3.4.1 --- CHANGELOG.md | 10 ++++++++++ package.json | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b224c1e..129726f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.4.1](https://github.com/alvis/presetter/compare/v3.4.0...v3.4.1) (2022-08-10) + + +### 🐛 Bug Fixes + +* **presetter:** merge arrays only if the values are all primitive ([961f30c](https://github.com/alvis/presetter/commit/961f30c8fcbf9ba6f6fbf9e4d90cf0cb8c5a1069)) +* update packages ([ec8307d](https://github.com/alvis/presetter/commit/ec8307d79468f8529b29a0f7b356b4368c03302c)) + + + # [3.4.0](https://github.com/alvis/presetter/compare/v3.3.0...v3.4.0) (2022-08-02) diff --git a/package.json b/package.json index d42945c..9aad04c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.4.0", + "version": "3.4.1", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.4.0", + "presetter": "^3.4.1", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", From 93a1ed2b0da58c3d877605643f9f887ced5fbb6d Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 23 Sep 2022 11:44:08 +0100 Subject: [PATCH 21/40] refactor(presetter): remove dependency on fs-extra --- source/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index f51cd43..275eb78 100644 --- a/source/index.ts +++ b/source/index.ts @@ -52,7 +52,7 @@ export default async function (): Promise { template: { /* eslint-disable @typescript-eslint/naming-convention */ 'rollup.config.ts': async (context) => { - const content = await loadFile( + const content = loadFile( resolve(TEMPLATES, 'rollup.config.ts'), 'text', ); From 21f28a21d2534f97e5b004ea95ce93b77bc17174 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 23 Sep 2022 13:21:03 +0100 Subject: [PATCH 22/40] refactor(rollup): remove unnecessary async waits --- source/index.ts | 6 +++--- source/rollup.ts | 4 ++-- spec/index.spec.ts | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/source/index.ts b/source/index.ts index 275eb78..05f8ae6 100644 --- a/source/index.ts +++ b/source/index.ts @@ -47,16 +47,16 @@ export const DEFAULT_VARIABLE: Variable = { * get the list of templates provided by this preset * @returns list of preset templates */ -export default async function (): Promise { +export default function (): PresetAsset { return { template: { /* eslint-disable @typescript-eslint/naming-convention */ - 'rollup.config.ts': async (context) => { + 'rollup.config.ts': (context) => { const content = loadFile( resolve(TEMPLATES, 'rollup.config.ts'), 'text', ); - const variable = await getRollupParameter(context); + const variable = getRollupParameter(context); return template(content, variable); /* eslint-enable @typescript-eslint/naming-convention */ diff --git a/source/rollup.ts b/source/rollup.ts index f5e9074..feca86e 100644 --- a/source/rollup.ts +++ b/source/rollup.ts @@ -61,9 +61,9 @@ interface IntermediateRollupConfig { * @param context context about the build environment * @returns template parameter related to rollup */ -export async function getRollupParameter( +export function getRollupParameter( context: ResolvedPresetContext, -): Promise> { +): Record<'rollupImport' | 'rollupExport', string> { const { config, variable } = context.custom; const normalizedConfig = template( diff --git a/spec/index.spec.ts b/spec/index.spec.ts index 2c4ef62..8ba838c 100644 --- a/spec/index.spec.ts +++ b/spec/index.spec.ts @@ -27,7 +27,7 @@ jest.mock('path', () => ({ describe('fn:getPresetAsset', () => { it('use all templates', async () => { - const asset = await getPresetAsset(); + const asset = getPresetAsset(); const context = await resolveContext({ graph: [{ name: 'preset', asset, nodes: [] }], context: { @@ -41,9 +41,9 @@ describe('fn:getPresetAsset', () => { await loadDynamicMap(asset.template, context); const TEMPLATES = resolve(__dirname, '..', 'templates'); - const allTemplates = await readdirSync(TEMPLATES); + const allTemplates = readdirSync(TEMPLATES); const CONFIGS = resolve(__dirname, '..', 'configs'); - const supplementaryConfig = await readdirSync(CONFIGS); + const supplementaryConfig = readdirSync(CONFIGS); for (const path of allTemplates) { expect(resolve).toBeCalledWith(TEMPLATES, path); From 57710e74740c552984c850a1738b35b0e60d4097 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 23 Sep 2022 14:18:27 +0100 Subject: [PATCH 23/40] build: move .presetterrc to the root --- .presetterrc.json | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 .presetterrc.json diff --git a/.presetterrc.json b/.presetterrc.json deleted file mode 100644 index 538771f..0000000 --- a/.presetterrc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "preset": "presetter-preset-strict", - "config": { - "npmignore": ["!/configs/**", "!/templates/**"] - }, - "variable": { - "root": "../.." - } -} From 0db2a739f077c41551ef59f80caa8546f591bf2d Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 23 Sep 2022 18:50:30 +0100 Subject: [PATCH 24/40] chore(release): publish v3.5.0 --- CHANGELOG.md | 15 +++++++++++++++ package.json | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 129726f..6675dab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +# [3.5.0](https://github.com/alvis/presetter/compare/v3.4.1...v3.5.0) (2022-09-23) + + +### 🛠 Builds + +* move .presetterrc to the root ([0eb17a0](https://github.com/alvis/presetter/commit/0eb17a058fa245faae96dcb017184460dae08b46)) + + +### 📦 Code Refactoring + +* **presetter:** remove dependency on fs-extra ([8810c56](https://github.com/alvis/presetter/commit/8810c568d1cf1de275b055916b6aeac450b43403)) +* **rollup:** remove unnecessary async waits ([9d9c4c3](https://github.com/alvis/presetter/commit/9d9c4c3b5131548512574634414214380cb501f2)) + + + ## [3.4.1](https://github.com/alvis/presetter/compare/v3.4.0...v3.4.1) (2022-08-10) diff --git a/package.json b/package.json index 9aad04c..524bd33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.4.1", + "version": "3.5.0", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.4.1", + "presetter": "^3.5.0", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", From d2cc99fae33c0b8d99639357b7546773b977e616 Mon Sep 17 00:00:00 2001 From: Alvis Tang Date: Sat, 18 Mar 2023 12:59:51 +0000 Subject: [PATCH 25/40] chore(release): publish v3.5.1 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6675dab..9f666b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.5.1](https://github.com/alvis/presetter/compare/v3.5.0...v3.5.1) (2023-03-18) + + + # [3.5.0](https://github.com/alvis/presetter/compare/v3.4.1...v3.5.0) (2022-09-23) diff --git a/package.json b/package.json index 524bd33..0018323 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.5.0", + "version": "3.5.1", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.5.0", + "presetter": "^3.5.1", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", From 26fa4da069a42cf8cd9fedef6e7f5ccaa97a64e6 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sun, 26 Mar 2023 08:46:08 +0100 Subject: [PATCH 26/40] chore(release): publish v3.5.2 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f666b3..5c5ff3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.5.2](https://github.com/alvis/presetter/compare/v3.5.1...v3.5.2) (2023-03-26) + + + ## [3.5.1](https://github.com/alvis/presetter/compare/v3.5.0...v3.5.1) (2023-03-18) diff --git a/package.json b/package.json index 0018323..d509243 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.5.1", + "version": "3.5.2", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.5.1", + "presetter": "^3.5.2", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", From 360aa8f073a9a0755f5310cff49205ea9816ec98 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sun, 26 Mar 2023 13:30:47 +0100 Subject: [PATCH 27/40] chore(release): publish v3.5.3 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c5ff3b..230982c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.5.3](https://github.com/alvis/presetter/compare/v3.5.2...v3.5.3) (2023-03-26) + + + ## [3.5.2](https://github.com/alvis/presetter/compare/v3.5.1...v3.5.2) (2023-03-26) diff --git a/package.json b/package.json index d509243..0ddec05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.5.2", + "version": "3.5.3", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.5.2", + "presetter": "^3.5.3", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", From f7f9f0ac7bdd2f21f351c98eb12806f6785c387c Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 30 Mar 2023 15:54:09 +0100 Subject: [PATCH 28/40] chore(release): publish v3.5.4 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 230982c..5d697bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.5.4](https://github.com/alvis/presetter/compare/v3.5.3...v3.5.4) (2023-03-30) + + + ## [3.5.3](https://github.com/alvis/presetter/compare/v3.5.2...v3.5.3) (2023-03-26) diff --git a/package.json b/package.json index 0ddec05..8de1b55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.5.3", + "version": "3.5.4", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.5.3", + "presetter": "^3.5.4", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", From 2e5652d84b7a8511fef33ae0114bb11ba5bf4ee6 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 31 Mar 2023 22:41:18 +0100 Subject: [PATCH 29/40] chore(release): publish v3.5.5 --- CHANGELOG.md | 4 ++++ package.json | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d697bf..cb100b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [3.5.5](https://github.com/alvis/presetter/compare/v3.5.4...v3.5.5) (2023-03-31) + + + ## [3.5.4](https://github.com/alvis/presetter/compare/v3.5.3...v3.5.4) (2023-03-30) diff --git a/package.json b/package.json index 8de1b55..bb20d82 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.5.4", + "version": "3.5.5", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", @@ -39,7 +39,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.5.4", + "presetter": "^3.5.5", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", From 57578e9398c861863ca331a58b13801af4a973d4 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Fri, 5 May 2023 19:20:29 +0800 Subject: [PATCH 30/40] style: make any node build-in modules explicitly imported first --- source/index.ts | 3 ++- spec/index.spec.ts | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/source/index.ts b/source/index.ts index 05f8ae6..518f271 100644 --- a/source/index.ts +++ b/source/index.ts @@ -13,7 +13,8 @@ * ------------------------------------------------------------------------- */ -import { resolve } from 'path'; +import { resolve } from 'node:path'; + import { loadFile, template } from 'presetter'; import { getRollupParameter } from './rollup'; diff --git a/spec/index.spec.ts b/spec/index.spec.ts index 8ba838c..eed1a9d 100644 --- a/spec/index.spec.ts +++ b/spec/index.spec.ts @@ -13,16 +13,16 @@ * ------------------------------------------------------------------------- */ -import { readdirSync } from 'fs'; -import { resolve } from 'path'; +import { readdirSync } from 'node:fs'; +import { resolve } from 'node:path'; import { loadDynamicMap, resolveContext } from 'presetter'; import getPresetAsset from '#index'; -jest.mock('path', () => ({ +jest.mock('node:path', () => ({ __esModule: true, - ...jest.requireActual('path'), - resolve: jest.fn(jest.requireActual('path').resolve), + ...jest.requireActual('node:path'), + resolve: jest.fn(jest.requireActual('node:path').resolve), })); describe('fn:getPresetAsset', () => { From 138002cd51b09f0dda7817ba3a6fbbe4d7ffa1f1 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 10 May 2023 19:15:12 +0800 Subject: [PATCH 31/40] fix(preset-rollup): inject NODE_ENV for build and develop stages --- templates/scripts.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/scripts.yaml b/templates/scripts.yaml index 8f5b630..865950f 100644 --- a/templates/scripts.yaml +++ b/templates/scripts.yaml @@ -1,5 +1,5 @@ # replace the `prepare` template from presetter-preset # so that the build procedure will not be triggered upon package installation -build: run-s clean build:rollup -build:rollup: cross-env NODE_ENV=production rollup --config rollup.config.ts --configPlugin rollup-plugin-ts -develop: run-s "build:rollup -- --watch {@}" -- +build: cross-env NODE_ENV=production run-s clean build:rollup +build:rollup: rollup --config rollup.config.ts --configPlugin rollup-plugin-ts +develop: cross-env NODE_ENV=development run-s "build:rollup -- --watch {@}" -- From ae48726a6c334088058f8379c8147ca50187bbc9 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sat, 3 Jun 2023 08:39:01 +0100 Subject: [PATCH 32/40] chore: allow tests can be done individually --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bb20d82..5ce4a44 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,13 @@ "scripts": { "bootstrap": "presetter bootstrap && run prepare", "build": "run build", - "coverage": "run coverage", - "lint": "run lint", + "coverage": "run coverage --", + "lint": "run lint --", "prepublishOnly": "run prepare && run prepublishOnly", "release": "run-s release:peer:*", "release:peer:presetter": "npm pkg set peerDependencies.presetter=^$(npx -c 'echo $npm_package_version')", - "test": "run test", - "watch": "run watch" + "test": "run test --", + "watch": "run watch --" }, "peerDependencies": { "@rollup/plugin-commonjs": "^22.0.0", From 5bb53481b04e61f6bb2cd62aae2950aceb2bb054 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Mon, 5 Jun 2023 13:55:42 +0100 Subject: [PATCH 33/40] feat(types): separate types from presetter --- package.json | 3 +++ source/index.ts | 3 ++- source/rollup.ts | 8 +++----- spec/rollup.spec.ts | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 5ce4a44..26f327d 100644 --- a/package.json +++ b/package.json @@ -50,5 +50,8 @@ "presetter": "file:../presetter", "presetter-preset-strict": "file:../preset-strict", "type-fest": "^2.0.0" + }, + "dependencies": { + "presetter-types": "file:../types" } } diff --git a/source/index.ts b/source/index.ts index 518f271..18cb5ad 100644 --- a/source/index.ts +++ b/source/index.ts @@ -19,8 +19,9 @@ import { loadFile, template } from 'presetter'; import { getRollupParameter } from './rollup'; +import type { PresetAsset } from 'presetter-types'; + import type { RollupConfig } from './rollup'; -import type { PresetAsset } from 'presetter'; // paths to the template directory const TEMPLATES = resolve(__dirname, '..', 'templates'); diff --git a/source/rollup.ts b/source/rollup.ts index feca86e..03dad14 100644 --- a/source/rollup.ts +++ b/source/rollup.ts @@ -23,17 +23,15 @@ import { import { assertPluginManifest } from './plugin'; +import type { ApplyDirective, ImportDirective } from 'presetter'; +import type { ResolvedPresetContext } from 'presetter-types'; + import type { PluginConfiguration, PluginList, PluginManifest, PluginObject, } from './plugin'; -import type { - ApplyDirective, - ImportDirective, - ResolvedPresetContext, -} from 'presetter'; /** preset configuration for rollup */ export interface RollupConfig { diff --git a/spec/rollup.spec.ts b/spec/rollup.spec.ts index 44c5c9c..453df85 100644 --- a/spec/rollup.spec.ts +++ b/spec/rollup.spec.ts @@ -15,7 +15,7 @@ import { getRollupParameter } from '#rollup'; -import type { Config, ResolvedPresetContext } from 'presetter'; +import type { Config, ResolvedPresetContext } from 'presetter-types'; describe('fn:getRollupParameter', () => { const generateContext = (config?: Config): ResolvedPresetContext => ({ From bc498596b835b4d600bf066938dcd47b4eab19d0 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 8 Jun 2023 10:50:25 +0100 Subject: [PATCH 34/40] feat: convert the whole project into ESM BREAKING CHANGE: - by default, client project emit ESM and for clarity preset-essentials has been renamed to preset-esm - ts-node is removed in favor of a more powerful and less buggy tsx --- README.md | 6 +++--- package.json | 2 +- source/index.ts | 9 ++++++--- spec/index.spec.ts | 41 ++++++++++++++++++++++++----------------- 4 files changed, 34 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 68d2912..d263a99 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ [**FULL DOCUMENTATION IS AVAILABLE HERE**](https://github.com/alvis/presetter/blob/master/README.md) -1. Bootstrap your project with `presetter-preset-essentials` & `presetter-preset-rollup` +1. Bootstrap your project with `presetter-preset-esm` & `presetter-preset-rollup` ```shell npx presetter use presetter-preset presetter-preset-rollup @@ -72,7 +72,7 @@ For NodeJS to import the correct export, remember to specify the following in yo ## Project Structure -After installation, your project file structure should resemble the following or with more configuration files if you also installed other presets such as [`presetter-preset-essentials`](https://github.com/alvis/presetter/blob/master/packages/preset-essentials). +After installation, your project file structure should resemble the following or with more configuration files if you also installed other presets such as [`presetter-preset-esm`](https://github.com/alvis/presetter/blob/master/packages/preset-essentials). Implement your business logic under `source` and prepare tests under `spec`. @@ -108,7 +108,7 @@ interface PresetterRC { name: string | string[]; /** additional configuration passed to the preset for generating the configuration files */ config?: { - // ┌─ configuration for other tools via other presets (e.g. presetter-preset-essentials) + // ┌─ configuration for other tools via other presets (e.g. presetter-preset-esm) // ... /** additional configuration for rollup */ diff --git a/package.json b/package.json index 26f327d..e30792e 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ }, "main": "lib/index.js", "types": "lib/index.d.ts", + "type": "module", "repository": { "type": "git", "url": "git+https://github.com/alvis/presetter.git" @@ -48,7 +49,6 @@ }, "devDependencies": { "presetter": "file:../presetter", - "presetter-preset-strict": "file:../preset-strict", "type-fest": "^2.0.0" }, "dependencies": { diff --git a/source/index.ts b/source/index.ts index 18cb5ad..2e691bd 100644 --- a/source/index.ts +++ b/source/index.ts @@ -13,7 +13,8 @@ * ------------------------------------------------------------------------- */ -import { resolve } from 'node:path'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; import { loadFile, template } from 'presetter'; @@ -23,9 +24,11 @@ import type { PresetAsset } from 'presetter-types'; import type { RollupConfig } from './rollup'; +const DIR = fileURLToPath(dirname(import.meta.url)); + // paths to the template directory -const TEMPLATES = resolve(__dirname, '..', 'templates'); -const CONFIGS = resolve(__dirname, '..', 'configs'); +const TEMPLATES = resolve(DIR, '..', 'templates'); +const CONFIGS = resolve(DIR, '..', 'configs'); /** config for this preset */ export type PresetConfig = { diff --git a/spec/index.spec.ts b/spec/index.spec.ts index eed1a9d..1e57354 100644 --- a/spec/index.spec.ts +++ b/spec/index.spec.ts @@ -13,21 +13,28 @@ * ------------------------------------------------------------------------- */ -import { readdirSync } from 'node:fs'; -import { resolve } from 'node:path'; -import { loadDynamicMap, resolveContext } from 'presetter'; +import { existsSync, readdirSync } from 'node:fs'; +import { dirname, resolve } from 'node:path'; +import * as pathNode from 'node:path'; +import { fileURLToPath } from 'node:url'; -import getPresetAsset from '#index'; +import { jest } from '@jest/globals'; -jest.mock('node:path', () => ({ - __esModule: true, - ...jest.requireActual('node:path'), - resolve: jest.fn(jest.requireActual('node:path').resolve), +const __dir = fileURLToPath(dirname(import.meta.url)); + +jest.unstable_mockModule('node:path', () => ({ + ...pathNode, + // spy on resolve to check if a template is referenced + resolve: jest.fn(resolve), })); +const { resolve: resolveSpyed } = await import('node:path'); +const { loadDynamicMap, resolveContext } = await import('presetter'); + +const { default: getPresetAsset } = await import('#index'); describe('fn:getPresetAsset', () => { it('use all templates', async () => { - const asset = getPresetAsset(); + const asset = await getPresetAsset(); const context = await resolveContext({ graph: [{ name: 'preset', asset, nodes: [] }], context: { @@ -40,16 +47,16 @@ describe('fn:getPresetAsset', () => { await loadDynamicMap(asset.supplementaryConfig, context); await loadDynamicMap(asset.template, context); - const TEMPLATES = resolve(__dirname, '..', 'templates'); - const allTemplates = readdirSync(TEMPLATES); - const CONFIGS = resolve(__dirname, '..', 'configs'); - const supplementaryConfig = readdirSync(CONFIGS); + const CONFIGS = resolve(__dir, '..', 'configs'); + const configs = (existsSync(CONFIGS) && readdirSync(CONFIGS)) || []; + const TEMPLATES = resolve(__dir, '..', 'templates'); + const templates = (existsSync(TEMPLATES) && readdirSync(TEMPLATES)) || []; - for (const path of allTemplates) { - expect(resolve).toBeCalledWith(TEMPLATES, path); + for (const path of configs) { + expect(resolveSpyed).toBeCalledWith(CONFIGS, path); } - for (const path of supplementaryConfig) { - expect(resolve).toBeCalledWith(CONFIGS, path); + for (const path of templates) { + expect(resolveSpyed).toBeCalledWith(TEMPLATES, path); } }); }); From 2a87e456b023d369d7230372bdaf9c6feda25d01 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sat, 10 Jun 2023 10:50:25 +0100 Subject: [PATCH 35/40] chore: use pnpm for workspace management --- package.json | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e30792e..9a9d621 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,6 @@ "coverage": "run coverage --", "lint": "run lint --", "prepublishOnly": "run prepare && run prepublishOnly", - "release": "run-s release:peer:*", - "release:peer:presetter": "npm pkg set peerDependencies.presetter=^$(npx -c 'echo $npm_package_version')", "test": "run test --", "watch": "run watch --" }, @@ -40,7 +38,7 @@ "@rollup/plugin-json": "^4.0.0", "@rollup/plugin-node-resolve": "^13.0.0", "@rollup/plugin-yaml": "^3.0.0", - "presetter": "^3.5.5", + "presetter": "workspace:*", "rollup": "^2.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", @@ -48,10 +46,10 @@ "rollup-plugin-visualizer": "^5.0.0" }, "devDependencies": { - "presetter": "file:../presetter", - "type-fest": "^2.0.0" + "presetter": "workspace:*" }, "dependencies": { - "presetter-types": "file:../types" + "presetter-types": "workspace:*", + "type-fest": "^2.0.0" } } From 4e671b72894f8467c30777c5675c327b04bedffa Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Tue, 13 Jun 2023 10:50:26 +0100 Subject: [PATCH 36/40] refactor(preset-rollup): normalize config in functional way --- source/rollup.ts | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/source/rollup.ts b/source/rollup.ts index 03dad14..403f683 100644 --- a/source/rollup.ts +++ b/source/rollup.ts @@ -180,20 +180,15 @@ function transformConfigValue(key: string, value: unknown): unknown { function objectifyPlugins( plugins: PluginManifest, ): IntermediateRollupConfig['plugins'] { - const normalizedPlugin: PluginObject = {}; - const pluginList: PluginConfiguration[] = Array.isArray(plugins) ? arrayToPluginConfiguration(plugins) : objectToPluginConfiguration(plugins); - for (const [name, options] of pluginList) { - Object.assign( - normalizedPlugin, + return pluginList.reduce( + (normalizedPlugin, [name, options]) => merge(normalizedPlugin, { [name]: options }), - ); - } - - return normalizedPlugin; + {}, + ); } /** From bbd74055a10d1a130bb7b2d3aa79e5afc9aae4b1 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Thu, 15 Jun 2023 10:50:26 +0100 Subject: [PATCH 37/40] fix: update outdated packages --- package.json | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9a9d621..f8407d0 100644 --- a/package.json +++ b/package.json @@ -32,14 +32,14 @@ "watch": "run watch --" }, "peerDependencies": { - "@rollup/plugin-commonjs": "^22.0.0", - "@rollup/plugin-graphql": "^1.0.0", - "@rollup/plugin-image": "^2.0.0", - "@rollup/plugin-json": "^4.0.0", - "@rollup/plugin-node-resolve": "^13.0.0", - "@rollup/plugin-yaml": "^3.0.0", + "@rollup/plugin-commonjs": "^25.0.0", + "@rollup/plugin-graphql": "^2.0.0", + "@rollup/plugin-image": "^3.0.0", + "@rollup/plugin-json": "^6.0.0", + "@rollup/plugin-node-resolve": "^15.0.0", + "@rollup/plugin-yaml": "^4.0.0", "presetter": "workspace:*", - "rollup": "^2.0.0", + "rollup": "^3.0.0", "rollup-plugin-postcss": "^4.0.0", "rollup-plugin-ts": "^3.0.0", "rollup-plugin-tsconfig-paths": "^1.0.0", @@ -50,6 +50,6 @@ }, "dependencies": { "presetter-types": "workspace:*", - "type-fest": "^2.0.0" + "type-fest": "^3.12.0" } } From 2e8a53c7a94f2754653c1ec4dfdd63083e192eab Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sat, 17 Jun 2023 15:20:03 +0100 Subject: [PATCH 38/40] fix(preset-rollup): make the rollup preset compatible with ESM --- configs/rollup.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/rollup.yaml b/configs/rollup.yaml index 035d5b5..a812de1 100644 --- a/configs/rollup.yaml +++ b/configs/rollup.yaml @@ -23,4 +23,4 @@ plugins: - - '@apply rollup-plugin-postcss[default]' - inject: insertAt: top - - '@apply rollup-plugin-visualizer[default]' + - '@apply rollup-plugin-visualizer[visualizer]' From 547dbc4a856a7b7896af44138dd35c5dc4e968cb Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Sun, 18 Jun 2023 08:00:01 +0100 Subject: [PATCH 39/40] chore(release): publish v4.0.0 --- CHANGELOG.md | 39 +++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb100b9..7d51202 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,45 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +# [4.0.0](https://github.com/alvis/presetter/compare/v3.5.5...v4.0.0) (2023-06-18) + + +### ✨ Features + +* convert the whole project into ESM ([381c84f](https://github.com/alvis/presetter/commit/381c84f59605faf9ce6c2b3f81c2eea81bfebc61)) +* **types:** separate types from presetter ([4ff3626](https://github.com/alvis/presetter/commit/4ff3626d915649208067b2235645e8534508f341)) + + +### 🐛 Bug Fixes + +* **preset-rollup:** inject NODE_ENV for build and develop stages ([b09ade5](https://github.com/alvis/presetter/commit/b09ade516250b8b5256d7f3d52ab1a30102607b5)) +* **preset-rollup:** make the rollup preset compatible with ESM ([86154b8](https://github.com/alvis/presetter/commit/86154b8daaf7e3f97c1a93753416263fe7b086dc)) +* update outdated packages ([bbaf33f](https://github.com/alvis/presetter/commit/bbaf33f0eaeaeca2c296cfc68207b4ff4632674f)) + + +### 📦 Code Refactoring + +* **preset-rollup:** normalize config in functional way ([f6b3815](https://github.com/alvis/presetter/commit/f6b3815a13309791852ba2442e0a48e6531f8d45)) + + +### ♻️ Chores + +* allow tests can be done individually ([b86f6ee](https://github.com/alvis/presetter/commit/b86f6eef689f7783a2a19841eaadf6e581dbb649)) +* use pnpm for workspace management ([358d0d7](https://github.com/alvis/presetter/commit/358d0d77cdc2b37affb36931f13568464f1a46ab)) + + +### 💎 Styles + +* make any node build-in modules explicitly imported first ([90730f2](https://github.com/alvis/presetter/commit/90730f2dfd27a6a6f1fbceb26ac5fb974e11508e)) + + +### Breaking changes + +* - by default, client project emit ESM and for clarity preset-essentials has been renamed to preset-esm +- ts-node is removed in favor of a more powerful and less buggy tsx + + + ## [3.5.5](https://github.com/alvis/presetter/compare/v3.5.4...v3.5.5) (2023-03-31) diff --git a/package.json b/package.json index f8407d0..da13c7b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "3.5.5", + "version": "4.0.0", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter", From a62e640bd98ea37968fa7dc71a4f4442bc9cb5f4 Mon Sep 17 00:00:00 2001 From: Alvis HT Tang Date: Wed, 21 Jun 2023 16:24:36 +0100 Subject: [PATCH 40/40] chore(release): publish v4.0.1 --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d51202..5e5f9bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [4.0.1](https://github.com/alvis/presetter/compare/v4.0.0...v4.0.1) (2023-06-21) + + + # [4.0.0](https://github.com/alvis/presetter/compare/v3.5.5...v4.0.0) (2023-06-18) diff --git a/package.json b/package.json index da13c7b..6eaa7ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "presetter-preset-rollup", - "version": "4.0.0", + "version": "4.0.1", "description": "An opinionated presetter preset for using rollup as a bundler", "keywords": [ "presetter",