Skip to content

Commit

Permalink
fix: include type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
wkillerud committed Aug 9, 2024
1 parent 7610052 commit d3c26ab
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 442 deletions.
22 changes: 9 additions & 13 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,24 @@ on:
- next

jobs:
test:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install
- run: npm install

- name: Lint files
run: npm run lint
- run: npm run lint

- name: Run tests
run: npm run test
- run: npm run types

- name: Run semantic release
run: npx semantic-release
- run: npm run test

- run: npx semantic-release
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- next

jobs:
build:
test:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
Expand All @@ -19,13 +19,14 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- run: npm install

- run: npm run lint

- run: npm run types

- run: npm test
115 changes: 3 additions & 112 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,114 +1,5 @@
node_modules
node_modules/**/*
.DS_Store
tmp/**/*
.idea
# Logs
logs
.idea/**/*
*.iml
*.log
npm-debug.log*
package-lock.json
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

.tap

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
.idea/
.tap/
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
types/
86 changes: 46 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ $ npm install @eik/esbuild-plugin
## Usage

```js
import * as eik from '@eik/esbuild-plugin';
import esbuild from 'esbuild';
import * as eik from "@eik/esbuild-plugin";
import esbuild from "esbuild";

await eik.load();

await esbuild.build({
entryPoints: ['./src/app.js'],
bundle: true,
format: 'esm',
target: ['esnext'],
plugins: [eik.plugin()],
entryPoints: ["./src/app.js"],
bundle: true,
format: "esm",
target: ["esnext"],
plugins: [eik.plugin()],
});
```

Expand All @@ -31,7 +31,7 @@ This plugin will read a local Eik config file (`eik.json`) and download the impo

### Plugin result

Bundles will have bare imports mapped to absolute URLs.
Bundles will have bare imports mapped to absolute URLs.

Ie. Something like this...

Expand All @@ -53,11 +53,11 @@ This module has the following API:

Loads an Eik configuration or import maps directly for the plugn to use to apply.

| option | default | type | required | details |
| ------- | -------------- | -------- | -------- | ----------------------------------------------------------- |
| path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. |
| urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
| maps | `[]` | `array` | `false` | Array of import map as objects. |
| option | default | type | required | details |
| ------ | -------------- | -------- | -------- | --------------------------------------- |
| path | `cwd/eik.json` | `string` | `false` | Path to eik.json file. |
| urls | `[]` | `array` | `false` | Array of import map URLs to fetch from. |
| maps | `[]` | `array` | `false` | Array of import map as objects. |

The plugin will attempt to read a `eik.json` from the current working directory of the Node.js process.

Expand All @@ -69,27 +69,29 @@ The path to the location of an `eik.json` file can be specified with the `path`

```js
await eik.load({
path: '/path/to/eik.json',
path: "/path/to/eik.json",
});
```

The plugin can also load import maps directly from one or multiple URLs using the `urls` option.

```js
await eik.load({
urls: ['http://myserver/import-maps/map.json'],
urls: ["http://myserver/import-maps/map.json"],
});
```

Additionally, individual import maps can be specified using the `maps` option.

```js
await eik.load({
maps: [{
imports: {
'lit-element': 'https://cdn.eik.dev/lit-element/v2',
}
}],
maps: [
{
imports: {
"lit-element": "https://cdn.eik.dev/lit-element/v2",
},
},
],
});
```

Expand All @@ -99,13 +101,15 @@ ie. in the following example

```js
await eik.load({
path: '/path/to/eik.json',
urls: ['http://myserver/import-maps/map.json'],
maps: [{
imports: {
'lit-element': 'https://cdn.eik.dev/lit-element/v2',
}
}],
path: "/path/to/eik.json",
urls: ["http://myserver/import-maps/map.json"],
maps: [
{
imports: {
"lit-element": "https://cdn.eik.dev/lit-element/v2",
},
},
],
});
```

Expand All @@ -116,26 +120,28 @@ Any import map URLs in `eik.json` will be loaded first, then merged with (and ov
Returns the plugin which will apply the loaded import maps during build. The returned plugin should be appended to the ESBuild plugin array.

```js
import * as eik from '@eik/esbuild-plugin';
import esbuild from 'esbuild';
import * as eik from "@eik/esbuild-plugin";
import esbuild from "esbuild";

await eik.load();

esbuild.build({
entryPoints: ['src/main.js'],
bundle: true,
format: 'esm',
minify: false,
sourcemap: false,
target: ['chrome58', 'firefox57', 'safari11', 'edge16'],
plugins: [eik.plugin()],
outfile: 'out.js',
}).catch(() => process.exit(1))
esbuild
.build({
entryPoints: ["src/main.js"],
bundle: true,
format: "esm",
minify: false,
sourcemap: false,
target: ["chrome58", "firefox57", "safari11", "edge16"],
plugins: [eik.plugin()],
outfile: "out.js",
})
.catch(() => process.exit(1));
```

### .clear()

Clears the loaded import maps from the plugins internal cache.
Clears the loaded import maps from the plugins internal cache.

## License

Expand Down
15 changes: 4 additions & 11 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import config from "@eik/eslint-config";

export default [
...config,
{
ignores: [
"tap-snapshots/*",
"node_modules/*",
"modules/*",
"utils/*",
"dist/*",
"tmp/*",
],
},
...config,
{
ignores: ["tap-snapshots/*", "node_modules/*", "fixtures/*"],
},
];
17 changes: 14 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
"description": "ESBuild plugin for loading import maps from a Eik server and applying the mapping to ECMAScript modules in preparation for upload to the same server.",
"type": "module",
"main": "./src/plugin.js",
"types": "./types/plugin.d.ts",
"files": [
"src"
"src",
"types"
],
"scripts": {
"test": "tap --disable-coverage --allow-empty-coverage",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix"
"lint:fix": "npm run lint -- --fix",
"types": "run-s types:module types:test",
"types:module": "tsc",
"types:test": "tsc --project tsconfig.test.json"
},
"repository": {
"type": "git",
Expand All @@ -35,12 +40,18 @@
"homepage": "https://github.com/eik-lib/esbuild-plugin#readme",
"devDependencies": {
"@eik/eslint-config": "1.0.2",
"@eik/prettier-config": "1.0.1",
"@eik/semantic-release-config": "1.0.0",
"@eik/typescript-config": "1.0.0",
"@types/esbuild-plugin-import-map": "0.0.3",
"esbuild": "0.23.0",
"eslint": "9.8.0",
"fastify": "4.28.1",
"npm-run-all": "4.1.5",
"prettier": "3.3.3",
"semantic-release": "24.0.0",
"tap": "20.0.3"
"tap": "20.0.3",
"typescript": "5.5.4"
},
"dependencies": {
"@eik/common": "3.0.1",
Expand Down
3 changes: 3 additions & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from "@eik/prettier-config";

export default config;
Loading

0 comments on commit d3c26ab

Please sign in to comment.