Skip to content

Commit

Permalink
Merge pull request #179 from chialab/remove-node-resolve-dep
Browse files Browse the repository at this point in the history
Remove node resolve dependency
  • Loading branch information
edoardocavazza authored Mar 8, 2024
2 parents 190e0ab + 4982505 commit 0ce12dd
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 29 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
9 changes: 8 additions & 1 deletion packages/esbuild-plugin-html/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,14 @@ export default function ({ scriptsTarget = 'es2015', modulesTarget = 'es2020', m
if (minify) {
await import('htmlnano')
.then(async ({ default: htmlnano }) => {
resultHtml = (await htmlnano.process(resultHtml, minifyOptions)).html;
resultHtml = (
await htmlnano.process(resultHtml, {
minifyJs: false,
minifyCss: false,
minifyJson: false,
...minifyOptions,
})
).html;
})
.catch(() => {
warnings.push({
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) {
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 URLSearchParams(source.split('?').slice(1).join('?')).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 0ce12dd

Please sign in to comment.