Skip to content

Commit

Permalink
breaking: Migrate to ESM only.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 8, 2021
1 parent 8ffb9c8 commit 5a7b10a
Show file tree
Hide file tree
Showing 8 changed files with 682 additions and 652 deletions.
3 changes: 3 additions & 0 deletions .config/beemo.ts
Expand Up @@ -12,4 +12,7 @@ export default {
},
],
],
settings: {
esm: true,
},
};
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -15,6 +15,7 @@ coverage/
dts/
esm/
lib/
mjs/
node_modules/

# Custom
Expand Down
2 changes: 2 additions & 0 deletions babel.config.js
@@ -1,3 +1,5 @@
process.env.PACKEMON_FORMAT = 'mjs';

const { createRootConfig } = require('packemon/babel');

module.exports = createRootConfig();
1 change: 1 addition & 0 deletions optimal/CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@ The biggest change is that predicates are now known as schemas. For the purpose
changelog will use the new verbiage, but may affect previous APIs.

- Dropped Node.js v10 support. Minimum requirement v12.17.
- Updated to ECMAScript modules, and now publishes `.mjs` for Node.js, and ESM `.js` for browsers.
- Updated `optimal()` to no longer accept the object to validate and build as the 1st argument. Instead a `validate()` function is returned, in which that object should be passed to. Because of this change, TypeScript types are more powerful and accurate.
- Updated the API to be immutable, so each chained method will return a new schema instance.
- Updated `array()` to no longer accept a schema as an argument, use `array().of()` instead.
Expand Down
26 changes: 22 additions & 4 deletions optimal/package.json
@@ -1,14 +1,15 @@
{
"name": "optimal",
"type": "module",
"version": "5.0.0-alpha.0",
"description": "A system for building and validating defined object structures with schemas.",
"main": "./lib/node/index.js",
"browser": "./lib/browser/index.js",
"main": "./mjs/index.mjs",
"module": "./esm/index.js",
"types": "./dts/index.d.ts",
"keywords": [
"opts",
"options",
"schema",
"predicate",
"validator",
"config",
Expand All @@ -30,7 +31,8 @@
"files": [
"dts/**/*.d.ts",
"esm/**/*.{js,map}",
"lib/**/*.{js,map}",
"mjs/**/*.{js,map}",
"mjs/**/*.{mjs,map}",
"src/**/*.{ts,tsx,json}"
],
"engines": {
Expand All @@ -44,12 +46,28 @@
"packemon": {
"bundle": true,
"format": [
"lib",
"mjs",
"esm"
],
"platform": [
"browser",
"node"
]
},
"devDependencies": {
"@jest/globals": "*"
},
"exports": {
"./package.json": "./package.json",
".": {
"browser": {
"import": "./esm/index.js",
"module": "./esm/index.js"
},
"node": {
"import": "./mjs/index.mjs"
},
"types": "./dts/index.d.ts"
}
}
}
4 changes: 3 additions & 1 deletion optimal/tests/schemas/runCommonTests.ts
@@ -1,3 +1,4 @@
import { jest } from '@jest/globals';
import { AnySchema, CommonCriterias, DefaultValue, Schema } from '../../src';

interface TestCriterias<S> extends CommonCriterias<S> {
Expand Down Expand Up @@ -57,6 +58,7 @@ export function runCommonTests<T>(
it('passes the current path and objects to the lazy callback function', () => {
const spy = jest.fn().mockReturnValue(defaultValue);

// @ts-expect-error Ignore type requirement
schema = factory(spy) as any;
schema.validate(undefined, 'key.deep', {
currentObject: { foo: '' },
Expand Down Expand Up @@ -223,7 +225,7 @@ export function runCommonTests<T>(
});

it('logs a message when validating', () => {
const spy = jest.spyOn(console, 'info').mockImplementation();
const spy = jest.spyOn(console, 'info').mockImplementation(() => {});

schema.deprecate('Migrate away!').validate(value, 'key', {});

Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"prepare": "beemo create-config",
"build": "packemon build --addEngines",
"pack": "NODE_ENV=production packemon pack --addEngines --declaration=standard",
"pack": "NODE_ENV=production packemon pack --addEngines --addExports --declaration=standard",
"check": "yarn run type && yarn run test && yarn run lint",
"clean": "packemon clean",
"coverage": "yarn run test --coverage",
Expand All @@ -21,9 +21,9 @@
"devDependencies": {
"@beemo/cli": "^2.0.1",
"@beemo/core": "^2.0.2",
"@beemo/dev": "^1.5.0",
"@types/node": "^15.6.1",
"packemon": "^1.4.1"
"@beemo/dev": "^1.6.0",
"@types/node": "^15.14.9",
"packemon": "^1.4.2"
},
"workspaces": [
"optimal/"
Expand Down

0 comments on commit 5a7b10a

Please sign in to comment.