Skip to content

Commit

Permalink
Remove node resolve dep
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardocavazza committed Mar 7, 2024
1 parent 190e0ab commit b67fc16
Show file tree
Hide file tree
Showing 17 changed files with 59 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .changeset/fast-spiders-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@chialab/esbuild-plugin-meta-url": patch
"@chialab/esbuild-plugin-worker": patch
"@chialab/esbuild-plugin-html": patch
---

Remove node-resolve plugin dependency.
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectAssets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isRelativeUrl } from '@chialab/node-resolve';
import { isRelativeUrl } from './utils.js';

/**
* @param {import('cheerio').CheerioAPI} $ The cheerio selector.
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectIcons.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from 'buffer';
import path from 'path';
import { isRelativeUrl } from '@chialab/node-resolve';
import { collectAsset } from './collectAssets.js';
import { generateIcon } from './generateIcon.js';
import Jimp from './generator.js';
import { isRelativeUrl } from './utils.js';

/**
* @typedef {Object} Icon
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectScreens.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Buffer } from 'buffer';
import path from 'path';
import { isRelativeUrl } from '@chialab/node-resolve';
import { collectAsset } from './collectAssets.js';
import { generateLaunch } from './generateLaunch.js';
import Jimp from './generator.js';
import { isRelativeUrl } from './utils.js';

/**
* @typedef {Object} Screen
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectScripts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { isRelativeUrl } from '@chialab/node-resolve';
import { isRelativeUrl } from './utils.js';

/**
* @param {import('cheerio').CheerioAPI} $ The cheerio selector.
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectStyles.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import { isRelativeUrl } from '@chialab/node-resolve';
import { isRelativeUrl } from './utils.js';

/**
* Collect and bundle each <link> reference.
Expand Down
2 changes: 1 addition & 1 deletion packages/esbuild-plugin-html/lib/collectWebManifest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Buffer } from 'buffer';
import path from 'path';
import { isRelativeUrl } from '@chialab/node-resolve';
import { generateIcon } from './generateIcon.js';
import Jimp from './generator.js';
import { isRelativeUrl } from './utils.js';

const MANIFEST_ICONS = [
{
Expand Down
20 changes: 20 additions & 0 deletions packages/esbuild-plugin-html/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { isAbsolute } from 'path';

/**
* Check if the given source is a relative url.
* @param {string | null | undefined} url The source to check.
*/
export function isRelativeUrl(url) {
if (url == null) {
return false;
}
if (isAbsolute(url)) {
return false;
}
try {
new URL(url);
return false;
} catch (err) {
return true;
}
}
3 changes: 1 addition & 2 deletions packages/esbuild-plugin-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
"node": ">=18"
},
"dependencies": {
"@chialab/esbuild-rna": "^0.18.1",
"@chialab/node-resolve": "^0.18.0"
"@chialab/esbuild-rna": "^0.18.1"
},
"peerDependencies": {
"htmlnano": "^2.0.0"
Expand Down
3 changes: 0 additions & 3 deletions packages/esbuild-plugin-html/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
"references": [
{
"path": "../esbuild-rna"
},
{
"path": "../node-resolve"
}
]
}
24 changes: 22 additions & 2 deletions packages/esbuild-plugin-meta-url/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@ import path from 'path';
import { fileURLToPath, pathToFileURL } from 'url';
import { useRna } from '@chialab/esbuild-rna';
import { getBlock, getIdentifierValue, getLocation, parse, TokenType, walk } from '@chialab/estransform';
import { getSearchParam, isUrl } from '@chialab/node-resolve';
import mime from 'mime-types';

/**
* Check if the given path is a valid url.
* @param {string} url
*/
function isUrl(url) {
try {
return !!new URL(url);
} catch (err) {
//
}
return false;
}

/**
* Get hash param (if available) in the url.
* @param {string} source
*/
export function getHashParam(source) {
return new URL(source).searchParams.get('hash') || null;
}

/**
* @param {import('@chialab/estransform').TokenProcessor} processor Token processor.
* @returns {string|undefined} The path value.
Expand Down Expand Up @@ -161,7 +181,7 @@ export default function ({ emit = true } = {}) {
return;
}

const id = getSearchParam(value, 'hash');
const id = getHashParam(value);
if (id && build.isEmittedPath(id)) {
return;
}
Expand Down
1 change: 0 additions & 1 deletion packages/esbuild-plugin-meta-url/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"dependencies": {
"@chialab/esbuild-rna": "^0.18.1",
"@chialab/estransform": "^0.18.0",
"@chialab/node-resolve": "^0.18.0",
"mime-types": "^2.1.35"
},
"devDependencies": {
Expand Down
3 changes: 0 additions & 3 deletions packages/esbuild-plugin-meta-url/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
},
{
"path": "../estransform"
},
{
"path": "../node-resolve"
}
]
}
5 changes: 2 additions & 3 deletions packages/esbuild-plugin-worker/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Buffer } from 'buffer';
import path from 'path';
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';
import metaUrlPlugin, { getHashParam } from '@chialab/esbuild-plugin-meta-url';
import { useRna } from '@chialab/esbuild-rna';
import { getBlock, getIdentifierValue, getLocation, parse, splitArgs, TokenType, walk } from '@chialab/estransform';
import { getSearchParam } from '@chialab/node-resolve';

/**
* @typedef {{ constructors?: string[], proxy?: boolean, emit?: boolean }} PluginOptions
Expand Down Expand Up @@ -216,7 +215,7 @@ export default function ({ constructors = ['Worker', 'SharedWorker'], proxy = fa
return;
}

const id = getSearchParam(value, 'hash');
const id = getHashParam(value);
if (id && build.isEmittedPath(id)) {
return;
}
Expand Down
3 changes: 1 addition & 2 deletions packages/esbuild-plugin-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"dependencies": {
"@chialab/esbuild-plugin-meta-url": "^0.18.0",
"@chialab/esbuild-rna": "^0.18.0",
"@chialab/estransform": "^0.18.0",
"@chialab/node-resolve": "^0.18.0"
"@chialab/estransform": "^0.18.0"
},
"devDependencies": {
"typescript": "^5.0.0"
Expand Down
3 changes: 0 additions & 3 deletions packages/esbuild-plugin-worker/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
},
{
"path": "../estransform"
},
{
"path": "../node-resolve"
}
]
}
3 changes: 0 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,6 @@ __metadata:
resolution: "@chialab/esbuild-plugin-html@workspace:packages/esbuild-plugin-html"
dependencies:
"@chialab/esbuild-rna": ^0.18.1
"@chialab/node-resolve": ^0.18.0
"@jimp/custom": ^0.22.0
"@jimp/jpeg": ^0.22.0
"@jimp/plugin-resize": ^0.22.0
Expand Down Expand Up @@ -1925,7 +1924,6 @@ __metadata:
dependencies:
"@chialab/esbuild-rna": ^0.18.1
"@chialab/estransform": ^0.18.0
"@chialab/node-resolve": ^0.18.0
"@types/mime-types": ^2.1.1
esbuild: ^0.19.0
mime-types: ^2.1.35
Expand Down Expand Up @@ -2003,7 +2001,6 @@ __metadata:
"@chialab/esbuild-plugin-meta-url": ^0.18.0
"@chialab/esbuild-rna": ^0.18.0
"@chialab/estransform": ^0.18.0
"@chialab/node-resolve": ^0.18.0
typescript: ^5.0.0
languageName: unknown
linkType: soft
Expand Down

0 comments on commit b67fc16

Please sign in to comment.