Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: ESM export #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.log*
coverage
dist
esm
node_modules
18 changes: 18 additions & 0 deletions configs/.babelrc-esm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"assumptions": {
"iterableIsArray": true
},
"presets": [
[
"@babel/preset-env",
{
"exclude": [
"@babel/plugin-transform-typeof-symbol"
],
"targets": "defaults",
"modules": false
}
],
"@babel/preset-flow"
]
}
2 changes: 1 addition & 1 deletion configs/.flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[version]
0.195.2
0.225.1

[ignore]

Expand Down
1 change: 1 addition & 0 deletions configs/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage
dist
esm
node_modules
3,604 changes: 1,884 additions & 1,720 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 17 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"version": "0.1.3",
"name": "styleq",
"main": "styleq.js",
"module": "dist/styleq.js",
"main": "./styleq.js",
"module": "./styleq.mjs",
"types": "./styleq.d.ts",
"esports": {
".": "./styleq.mjs"
},
"sideEffects": false,
"license": "MIT",
"description": "A quick JavaScript runtime for Atomic CSS compilers.",
Expand All @@ -15,7 +19,9 @@
],
"scripts": {
"benchmark": "node test/benchmark.node.js",
"build": "babel src --out-dir dist --config-file ./configs/.babelrc",
"build-cjs": "babel src --out-dir dist --config-file ./configs/.babelrc",
"build-esm": "babel src --out-dir esm --config-file ./configs/.babelrc-esm",
"build": "npm run build-cjs && npm run build-esm",
"flow": "flow --flowconfig-name ./configs/.flowconfig",
"jest": "jest ./test",
"lint": "npm run lint:report -- --fix",
Expand All @@ -26,18 +32,18 @@
"test": "npm run flow && npm run prettier:report && npm run lint:report && npm run jest"
},
"devDependencies": {
"@babel/cli": "^7.13.10",
"@babel/core": "^7.15.5",
"@babel/eslint-parser": "^7.15.8",
"@babel/plugin-syntax-flow": "^7.12.13",
"@babel/preset-env": "^7.15.6",
"@babel/preset-flow": "^7.14.5",
"@babel/types": "^7.15.6",
"@babel/cli": "^7.23.4",
"@babel/core": "^7.23.6",
"@babel/eslint-parser": "^7.23.3",
"@babel/plugin-syntax-flow": "^7.23.3",
"@babel/preset-env": "^7.23.6",
"@babel/preset-flow": "^7.23.3",
"@babel/types": "^7.23.6",
"benchmark": "^2.1.4",
"eslint": "^7.32.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-flowtype": "^7.0.0",
"flow-bin": "^0.195.2",
"flow-bin": "^0.225.1",
"jest": "^27.2.4",
"prettier": "^2.4.1"
},
Expand Down
8 changes: 4 additions & 4 deletions src/styleq.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
CompiledStyle,
InlineStyle,
Styles,
} from '../styleq.flow';
} from '../styleq.js.flow';

type Cache = WeakMap<CompiledStyle, [string, Array<string>, Cache]>;

Expand All @@ -36,7 +36,7 @@ function createStyleq(options?: StyleqOptions): Styleq {

return function styleq() {
// Keep track of property commits to the className
const definedProperties = [];
const definedProperties: Array<string> = [];
// The className and inline style to build up
let className = '';
let inlineStyle: null | InlineStyle = null;
Expand Down Expand Up @@ -116,7 +116,7 @@ function createStyleq(options?: StyleqOptions): Styleq {
// Cache: write
if (nextCache != null) {
// Create the next WeakMap for this sequence of styles
const weakMap = new WeakMap();
const weakMap: Cache = new WeakMap();
nextCache.set(style, [
classNameChunk,
definedPropertiesChunk,
Expand Down Expand Up @@ -176,7 +176,7 @@ function createStyleq(options?: StyleqOptions): Styleq {
};
}

const styleq: IStyleq = createStyleq();
const styleq: IStyleq = (createStyleq(): $FlowFixMe);
styleq.factory = createStyleq;

export { styleq };
1 change: 1 addition & 0 deletions styleq.flow.js → styleq.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ export type Styleq = (styles: Styles) => StyleqResult;
export type IStyleq = {
(...styles: $ReadOnlyArray<Styles>): StyleqResult,
factory: (options?: StyleqOptions) => Styleq,
...
};
8 changes: 8 additions & 0 deletions styleq.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Copyright (c) Nicolas Gallagher
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

export { styleq } from './esm/styleq';
Loading