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
This commit is contained in:
parent
5bb53481b0
commit
bc498596b8
|
@ -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 */
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue