Skip to content

Commit

Permalink
feat: bundle along type definitions (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Oct 7, 2021
1 parent cc99e5a commit 3e32e56
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 48 deletions.
26 changes: 22 additions & 4 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { build as esBuild } from 'esbuild';
import { copyFileSync, readdirSync, unlinkSync } from 'fs';
import {
closeSync,
copyFileSync,
openSync,
readdirSync,
readFileSync,
unlinkSync,
writeSync,
} from 'fs';
import { join } from 'path';

const copyFiles = (src: string, dest = src): void => {
Expand All @@ -18,13 +26,23 @@ void esBuild({
target: 'es5',
})
.then(() => {
const files = readdirSync(join(__dirname, 'dist'));
files.forEach((file) => {
if (file !== 'index.min.js') unlinkSync(join(__dirname, 'dist', file));
readdirSync(join(__dirname, 'dist')).forEach((file) => {
if (!/^index(\.min\.js|\.d\.ts)$/.test(file)) unlinkSync(join(__dirname, 'dist', file));
});

copyFiles('.npmignore LICENSE README.md');
copyFiles('package-dist.json', 'package.json');

// merge type declarations
const fd = openSync(join(__dirname, 'dist', 'index.d.ts'), 'w+');
writeSync(
fd,
`${readFileSync(join(__dirname, 'types', 'base.d.ts'))}
${readFileSync(join(__dirname, 'dist', 'index.d.ts'))}`.replace(/\s+$/g, '\n'),
);
closeSync(fd);

//
})
.catch((err) => {
console.error(err);
Expand Down
22 changes: 18 additions & 4 deletions package-dist.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
{
"$schema": "https://json.schemastore.org/package.json",
"name": "animated-tailwindcss",
"version": "2.3.2",
"description": "A configuration to use Animate.css with Tailwind CSS",
"license": "MIT",
"author": "Divyansh Singh <divyansh.singh@ikcb.org> (https://github.com/brc-dd)",
"repository": "https://github.com/ikcb/animated-tailwindcss",
"contributors": [
"Akash Tureha <2020kucp1138@iiitkota.ac.in> (https://github.com/MrMischievousX)"
],
"homepage": "https://ikcb.org/animated-tailwindcss",
"repository": "github:ikcb/animated-tailwindcss",
"bugs": {
"url": "https://github.com/ikcb/animated-tailwindcss/issues",
"email": "codebase@iiitkota.ac.in"
},
"main": "index.min.js",
"files": [
"*.js"
],
"scripts": {},
"types": "index.d.ts",
"dependencies": {
"lodash.get": "4.4.2",
"lodash.set": "4.3.2"
"csstype": "^3.0.9",
"lodash.get": "^4.4.2",
"lodash.set": "^4.3.2"
},
"peerDependencies": {
"postcss": ">=7.0.0",
"tailwindcss": ">=1.6.0"
},
"keywords": [
Expand All @@ -26,6 +37,9 @@
"tailwind",
"tailwindcss"
],
"engines": {
"node": ">=8.9.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"allowJs": false,
"baseUrl": "src",
"declaration": true,
"downlevelIteration": true,
"esModuleInterop": true,
"module": "commonjs",
Expand All @@ -13,5 +14,5 @@
"strict": true,
"target": "es5"
},
"exclude": ["build.ts"]
"exclude": ["build.ts", "dist/**/*"]
}
14 changes: 14 additions & 0 deletions types/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type CSSBlock = import('./base').CSSBlock;
type EntryPoint = import('./base').EntryPoint;
type Keyframes = Record<string, Record<string, import('./base').CSSProperties>>;
type KeyValuePair = import('./base').KeyValuePair;
type PluginsConfig = import('./base').PluginsConfig;

declare module 'tailwindcss/lib/util/createUtilityPlugin' {
const createUtilityPlugin: (
themeKey: string,
utilityVariations?: Array<unknown>,
) => import('./base').PluginCreator;

export = createUtilityPlugin;
}
21 changes: 7 additions & 14 deletions types/index.d.ts → types/base.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// https://github.com/tailwindlabs/play.tailwindcss.com/tree/master/src/monaco/ *.d.ts

import type * as CSS from 'csstype';
import type * as postcss from 'postcss';

type KeyValuePair<TKey extends keyof never = string, TValue = string> = Record<TKey, TValue>;

type ConfigUtils = {
Expand Down Expand Up @@ -278,7 +281,7 @@ type PluginAPI = {
addVariant: (
name: string,
generator: (api: {
container: import('postcss').Container;
container: postcss.Container;
separator: string;
modifySelectors: (
modifierFunction: (api: { className: string; selector: string }) => void,
Expand All @@ -299,7 +302,7 @@ type PluginAPI = {

corePlugins: (path: string) => boolean;

postcss: typeof import('postcss');
postcss: typeof postcss;
};

type PluginCreator = (api: PluginAPI) => void;
Expand All @@ -324,18 +327,8 @@ type TailwindConfig = Partial<
}
>;

// ====================================== additional types ====================================== //
type CSSProperties = CSS.Properties & Record<`--${string}`, string>;

type CSSProperties = Record<`--${string}`, string> & import('csstype').Properties;
type CSSBlock = Record<string, CSSProperties | Record<string, CSSProperties>>;
type Keyframes = Record<string, Record<string, CSSProperties>>;
type EntryPoint = (config: TailwindConfig, _: { experimental?: boolean }) => TailwindConfig;

declare module 'tailwindcss/lib/util/createUtilityPlugin' {
const createUtilityPlugin: (
themeKey: string,
utilityVariations?: Array<unknown>,
) => PluginCreator;

export = createUtilityPlugin;
}
type EntryPoint = (config: TailwindConfig, _: { experimental?: boolean }) => TailwindConfig;
33 changes: 8 additions & 25 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"@babel/highlight" "^7.10.4"

"@babel/code-frame@^7.0.0":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.14.5.tgz#23b08d740e83f49c5e59945fbf1b43e80bbf4edb"
integrity sha512-9pzDqyc6OLDaqe+zbACgFkb6fKMNG6CObKpnYXChRsvYGyEdc7CA2BaqeOM+vOtCS5ndmJicPJhKAwYRI6UfFw==
version "7.15.8"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.15.8.tgz#45990c47adadb00c03677baa89221f7cc23d2503"
integrity sha512-2IAnmn8zbvC/jKYhq5Ki9I+DwjlrtMPUCH/CpHvqI4dNnlwHwsxoIhlc8WcYY5LSYknXQtAlFYuHfqAFCvQ4Wg==
dependencies:
"@babel/highlight" "^7.14.5"

Expand Down Expand Up @@ -2971,25 +2971,13 @@ mime-db@1.49.0:
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.49.0.tgz#f3dfde60c99e9cf3bc9701d687778f537001cbed"
integrity sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==

mime-db@1.50.0:
version "1.50.0"
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.50.0.tgz#abd4ac94e98d3c0e185016c67ab45d5fde40c11f"
integrity sha512-9tMZCDlYHqeERXEHO9f/hKfNXhre5dK2eE/krIvUjZbS2KPcqGDfNShIWS1uW9XOTKQKqK6qbeOci18rbfW77A==

mime-types@2.1.32:
mime-types@2.1.32, mime-types@^2.1.12:
version "2.1.32"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.32.tgz#1d00e89e7de7fe02008db61001d9e02852670fd5"
integrity sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==
dependencies:
mime-db "1.49.0"

mime-types@^2.1.12:
version "2.1.33"
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.33.tgz#1fa12a904472fafd068e48d9e8401f74d3f70edb"
integrity sha512-plLElXp7pRDd0bNZHw+nMd52vRYjLwQjygaNg7ddJ2uJtTlmnTCjWuPKxVu6//AdaRuME84SvLW91sIkBqGT0g==
dependencies:
mime-db "1.50.0"

mimic-fn@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b"
Expand Down Expand Up @@ -3041,16 +3029,11 @@ ms@2.0.0:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=

ms@2.1.2:
ms@2.1.2, ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

ms@^2.1.1:
version "2.1.3"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2"
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==

mute-stream@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
Expand Down Expand Up @@ -3870,9 +3853,9 @@ rxjs@^6.6.7:
tslib "^1.9.0"

rxjs@^7.2.0:
version "7.3.1"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.3.1.tgz#cc375521f9e238b474fe552b0b9fd1be33d08099"
integrity sha512-vNenx7gqjPyeKpRnM6S5Ksm/oFTRijWWzYlRON04KaehZ3YjDwEmVjGUGo0TKWVjeNXOujVRlh0K1drUbcdPkw==
version "7.4.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.4.0.tgz#a12a44d7eebf016f5ff2441b87f28c9a51cebc68"
integrity sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==
dependencies:
tslib "~2.1.0"

Expand Down

0 comments on commit 3e32e56

Please sign in to comment.