Git Product home page Git Product logo

esbuild-plugins's Introduction

esbuild-plugins's People

Contributors

almaraubel avatar alykamb avatar jcvalerio avatar linbudu599 avatar vicary avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

esbuild-plugins's Issues

Copy plugin "is not a function"

I'm working on an esbuild configuration and want to copy a file (manifest.json) to a specific folder when I build my project for testing purposes. I included the copy plugin into my esbuild-config.mjs

import esbuild from "esbuild";
import process from "process";
import builtins from 'builtin-modules'
import copy from 'esbuild-plugin-copy';

const prod = (process.argv[2] === 'production');
    
const baseConfig = {
    // ...
};

const testVaultPluginFolder = 'test-vault/.obsidian/plugins/obsidian-sample-plugin/';
const devConfig = {
	...baseConfig,
	outfile: testVaultPluginFolder + 'main.js',
	plugins: [
		copy({  // <- This line causes the problem
			assets: [
				{ from: ['manifest.json'], to: [testVaultPluginFolder] }
			]
		})
	]
};

const prodConfig = {
	...baseConfig,
	outfile: 'main.js',
};

if (prod){
	esbuild.build(prodConfig).catch(() => process.exit(1));
} else {
	esbuild.build(devConfig).catch(() => process.exit(1));
}

I can even Ctrl + Click into the copy function in VS Code.

Then when I run it it tells me that copy is not a function:

$ npm run dev

> [email protected] dev C:\Workspaces\RNSS-Sample\obsidian-sample-plugin
> node esbuild.config.mjs

file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:59
                copy({
                ^

TypeError: copy is not a function
    at file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:59:3
    at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async Object.loadESM (internal/process/esm_loader.js:68:5)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `node esbuild.config.mjs`
npm ERR! Exit status 1

Edit: Further research

I found this question where the copy (to clipboard) function produced the same error: https://stackoverflow.com/questions/62212958/devtools-console-copy-is-not-a-function-while-on-youtube

The problem was, that the DOM contained another element named copy that was not a function. Even though I'm not in a Browser here, I tried renaming the import.

import copyIsADamnFunction from 'esbuild-plugin-copy';

plugins: [
	copyIsADamnFunction({
		assets: [
			{ from: ['manifest.json'], to: [testVaultPluginFolder] }
		]
	})
]

Same result:

TypeError: copyIsADamnFunction is not a function
    at file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:59:3

When I remove the import I get

ReferenceError: copy is not defined
    at file:///C:/Workspaces/.../obsidian-sample-plugin/esbuild.config.mjs:58:11

So the import imports something. And VS Code tells me on mouse over that copy is a function with one optional parameter returning a esbuild.Plugin:

(alias) copy(options?: Partial<Options>): esbuild.Plugin
import copy

If I write copy. VS Code even offers me code completion like apply, arguments, bind and call which all belong to Function.prototype. How can copy not be a function?

copy: looks like not support copy filename

#!/usr/bin/env node

import { build } from 'esbuild'
import { join } from 'path'
import { copy } from 'esbuild-plugin-copy';
import { main as outfile_main } from './package.json';

import { sassPlugin } from 'esbuild-sass-plugin'
import { __ROOT, __ROOT_OUTPUT } from './test/__root';

(async () => {
	console.log(`build`, __ROOT_OUTPUT)
	console.log(`outfile`, outfile_main)

	await build({
		entryPoints: [
			join(__ROOT, 'src/index.mts')
		],
		outfile: join(__ROOT_OUTPUT, 'javascript', outfile_main),
		bundle: true,
		plugins: [
			sassPlugin({
				type: "css-text",
			}),
			copy({
				assets: [
					{
						from: [
							'./scripts/**/*'
						],
						to: [
							'./output/scripts'
						],
					},
					{
						from: [
							'./README\.md',
							'LICENSE',
						],
						to: [
							'./output'
						],
					},
					{
						from: [
							'./\.github',
						],
						to: [
							'./output/.github'
						],
					},
				],
				verbose: true,
				resolveFrom: __ROOT,
			}),
		],
		platform: 'browser',
		treeShaking: true,
		sourcemap: true,
		// @ts-ignore
		//analyze: true,
		legalComments: 'none',
		allowOverwrite: true,
		minifySyntax: true,
		format: 'iife',
		minify: Boolean(process.env['ESBUILD_MINIFY'])
	})
})();

image

image

`to` is treated as a file if directory contains a dot

When specifying a glob for the from property, and using a folder name with a dot for to, the result is a file that's few bytes large instead of a folder containing all the glob matches.

Trivial example:

...
{
  from: './**/*',
  to: './foo.bar'
}

Feature Request: Add 'once' to the esbuild-plugin-copy

Currently the copy plugin runs on every build (during watch). However, in most situations its just fine to only do the copy on the first cycle to prevent unnecessary resources and disk writing being done on each code change.

I suggest expanding the options to:

export interface Options {
  // assets pair to copy
  assets: MaybeArray<AssetPair>;
  // start copy on onStart hooks instead of onEnd
  // default: false
  copyOnStart: boolean;
  // verbose logging
  // default: true
  verbose: boolean;
  // extra globby options for paths matching, will be passed to globby directly
  globbyOptions: GlobbyOptions;
  // only run the copy once
  // default: false
  once: boolean;
}

[nx-plugin-vite] Missing dependencies declaration

Hello,

I'm trying to use the nx-plugin-vite on a brand new NX monorepo and the following command is failing:
yarn nx g nx-plugin-vite:app sandbox --framework=react --dryRun

Output

>  NX  Generating nx-plugin-vite:app
 
  >  NX   Cannot find module 'lodash/merge'

   Require stack:
   - /Users/ricardo/Workspace/bank/node_modules/nx-plugin-devkit/src/lib/generator-utils/package-json.js
   - /Users/ricardo/Workspace/bank/node_modules/nx-plugin-devkit/src/index.js
   - /Users/ricardo/Workspace/bank/node_modules/nx-plugin-vite/src/generators/app/generator.js
   - /Users/ricardo/Workspace/bank/node_modules/nx/src/config/workspaces.js
   - /Users/ricardo/Workspace/bank/node_modules/nx/src/config/configuration.js
   - /Users/ricardo/Workspace/bank/node_modules/nx/src/command-line/generate.js
   - /Users/ricardo/Workspace/bank/node_modules/nx/src/command-line/nx-commands.js
   - /Users/ricardo/Workspace/bank/node_modules/nx/bin/init-local.js
   - /Users/ricardo/Workspace/bank/node_modules/nx/bin/nx.js
   Pass --verbose to see the stacktrace.

If I add lodash and esbuild as devDependencies in the top-level package.json, then the command succeeds.

Since it is nx-plugin-devkit that requires esbuild and lodash as dependencies, I believe nx-plugin-vite should include them in dependencies so that users of the plugin do not need to worry about those dependencies.

Expected Output

>  NX  Generating nx-plugin-vite:app

CREATE apps/sandbox/project.json
CREATE apps/sandbox/index.html
CREATE apps/sandbox/package.json
CREATE apps/sandbox/src/App.css
CREATE apps/sandbox/src/App.tsx
CREATE apps/sandbox/src/favicon.svg
CREATE apps/sandbox/src/index.css
CREATE apps/sandbox/src/logo.svg
CREATE apps/sandbox/src/main.tsx
CREATE apps/sandbox/src/vite-env.d.ts
CREATE apps/sandbox/tsconfig.json
CREATE apps/sandbox/vite.config.ts
UPDATE package.json

NOTE: The "dryRun" flag means no changes were made.

None of these warnings being shown when running yarn install:

➤ YN0002: │ nx-plugin-vite@npm:2.2.1 [47fe8] doesn't provide @nrwl/devkit (paf740), requested by nx-plugin-devkit
➤ YN0002: │ nx-plugin-vite@npm:2.2.1 [47fe8] doesn't provide @nrwl/node (p7e761), requested by nx-plugin-devkit
➤ YN0002: │ nx-plugin-vite@npm:2.2.1 [47fe8] doesn't provide @nrwl/tao (pdd3db), requested by nx-plugin-devkit
➤ YN0002: │ nx-plugin-vite@npm:2.2.1 [47fe8] doesn't provide @nrwl/workspace (p7d1f4), requested by nx-plugin-devkit
➤ YN0002: │ nx-plugin-vite@npm:2.2.1 [47fe8] doesn't provide esbuild (p955e1), requested by nx-plugin-devkit

NX Report

 >  NX   Report complete - copy this into the issue template

   Node : 18.10.0
   OS   : darwin arm64
   yarn : 3.2.3

   nx : 14.8.3
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.8.3
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 14.8.3
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 14.8.3
   @nrwl/js : 14.8.3
   @nrwl/linter : 14.8.3
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 14.8.3
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : 14.8.3
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 14.8.3
   @nrwl/workspace : 14.8.3
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
   	 @nx-extend/playwright: 1.1.0
   	 @nxext/vitest: 14.0.2
   	 nx-plugin-vite: 2.2.1

esbuild-plugin-copy: Named export not found

Hi, I'm running into the following issue if I don't use version 1.3.0

import { copy }  from "esbuild-plugin-copy";
         ^^^^
SyntaxError: Named export 'copy' not found. The requested module 'esbuild-plugin-copy' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'esbuild-plugin-copy';
const { copy } = pkg;

If I change the code to the suggestion it gives me a different error. removing the {} gives me also an error.

nx-plugin-vite does not work with @netlify-builder/deploy:deploy

When i try to automate a build & deploy to netlify with this builder:

  // File: project.json
    "deploy": {
      "executor": "@netlify-builder/deploy:deploy",
      "options": {
        "outputPath": "dist/apps/thunder",
        "siteId": "16d309af-627a-471e-a5ec-8d739bbeb358",
        "noBuild": false,
        "buildTarget": "build"
      }
    },

    "build": {
      "executor": "nx-plugin-vite:build",
      "defaultConfiguration": "production",
      "configurations": {
        "production": {
          "outDir": "dist/apps/thunder",
          "configFile": "apps/thunder/vite.config.ts",
          "watch": false,
          "write": true,
          "emitAtRootLevel": true,
          "manifest": true
        }
      }
    }

Error output

It doesn't work and it shows error: Package "nx-plugin-vite" has no builders defined..
Maybe i can help with 'define' the builder. But it doesn't work. I've tried changing the configuration value to options like this
before:

  // File: project.json

    "build": {
      "executor": "nx-plugin-vite:build",
      "defaultConfiguration": "production",
      "configurations": {
        "production": {
          "outDir": "dist/apps/thunder",
          "configFile": "apps/thunder/vite.config.ts",
          "watch": false,
          "write": true,
          "emitAtRootLevel": true,
          "manifest": true
        }
      }
    }

after:

  // File: project.json

    "build": {
      "executor": "nx-plugin-vite:build",
      "options": {
          "outDir": "dist/apps/thunder",
          "configFile": "apps/thunder/vite.config.ts",
          "watch": false,
          "write": true,
          "emitAtRootLevel": true,
          "manifest": true
        }
    }

But none of them worked

[esbuild-plugin-copy] Feature request: throw when no files matched

Hello, currently if an input to path is incorrect the only notification is a log if verbose is enabled. It'd be great to have a setting to error in this case to highlight that something is wrong

if (!deduplicatedPaths.length) {
verboseLog(
`No files matched using current glob pattern: ${chalk.white(
from
)}, maybe you need to configure globby by ${chalk.white(
'options.globbyOptions'
)}?`,
verbose
);
}

Let me know if you'd be open to a PR for this.

Thanks for the plugin!

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) -- Using esbuild-plugin-alias-path

I tried it and added to tsup plugins, just like that put throws out that error.

import { defineConfig } from 'tsup';
import { aliasPath as esbuildPluginAliasPath } from 'esbuild-plugin-alias-path';

import path from 'node:path';

export default defineConfig({
  bundle: true,
  clean: true,
  dts: false,
  entry: ['source/**/*.ts', '!source/**/*.d.ts'],
  format: ['cjs'],
  minify: process.env.NODE_ENV == 'development' ? false : true,
  outDir: 'dist/bot',
  tsconfig: 'tsconfig.json',
  target: 'es2018',
  silent: true,
  plugins: [
    esbuildPluginAliasPath({
      alias: {
        "@config": path.resolve(__dirname, "./dist/bot/config.js"),
        "@library/*": path.resolve(__dirname, "./dist/bot/library/"),
        "@translations/*": path.resolve(__dirname, "./translations/"),
        "@root/*": path.resolve(__dirname, "./")
      }
    })
  ],
  splitting: false,
  skipNodeModulesBundle: true,
  sourcemap: true,
  shims: false,
  keepNames: true
});
TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
    at file:///C:/Users/PC/OneDrive/Documents/project/node_modules/esbuild-plugin-alias-path/dist/index.mjs:20:30
    at Array.forEach (<anonymous>)

I'm back!

At first, I'd like to thank all users of sub-packages belongs to this repo, and apologize for the poor maintenance behavior.

My focus has not been on this project for some time, so naturally I left it alone. Happily, I'm now ready to put it back on the agenda!(Start from this weekend)

Part of the refactoring and enhancement work I will be doing are listed below:

  • Migrate to pnpm workspace.
  • Update Nx version.
  • Update peer deps version(ESBuild/Vite/Prisma...).
  • Workflow enhancement with changesets & pnpm workspace.
  • Support both ESM and CJS for corresponding usage(require/import).
  • ...More

[esbuild-plugin-copy] Copy only if file has changed

The copying should happen only if a file has changed. This would make the plugin behave much better with watch enabled in esbuild.

Even simple comparison of last modify date would do it in most cases.

Would be made better if it cached the stat calls for the target files.

esbuild-plugin-copy: keep directory structure

How do I keep the directory structure when copying?

assets: [ {
    from: [ './node_modules/tinymce/skins/**/*' ],
    to: [ './js/skins' ],
} ]

This merges all files within the root directory /js/skins/ and doesn't preserve the original directory structure.

Transpile then copy?

I would like to transpile my TS files into JS and then use the copy plugin to copy it over to the output folder.

Currently the copy works well, I have the current build step config

await build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  minify: true,
  platform: 'node',
  outfile: 'dist/app.js',
  plugins: [
    copy({
      resolveFrom: 'cwd',
      assets: {
        from: ['./src/db/migrations/*'],
        to: ['./dist/db/migrations/'],
      },
      watch: true,
    }),
  ],
});

I'm looking for a way to add the transpile step on top.

Import from lib folder

Thanks for the excellent work combining nx and vite. how do i import an nx lib into my vite vue application. what is the tsconfig changes it requires so i can import it with the prefix? do we have an example with app importing from libs?

[esbuild-plugin-compress] Add zstd support

Chrome was doing an origin trial of zstd compression, and just shipped it in Chrome v123: https://chromestatus.com/feature/6186023867908096. Mozilla also just landed it in nightly builds (mozilla/standards-positions#775 (comment))

zstd is faster than Brotli while also usually having a better compression ratio. It would be nice for this plugin to support it.

There are a few Node.js modules that implement zstd, for example https://www.npmjs.com/package/@skhaz/zstd.

[bug] The build does not work when updating to NX 13.10.*

Hi there,
When migrating to version 13.10.2, an error crashes:

node:internal/modules/cjs/loader:933
  const err = new Error(message);
              ^

Error: Cannot find module 'nx/tasks-runners/default'
Require stack:
- /Users/a.blackoff/Project/thesollution/thesollution/node_modules/@nrwl/workspace/src/tasks-runner/run-command.js
- /Users/a.blackoff/Project/thesollution/thesollution/node_modules/@nrwl/workspace/src/command-line/run-one.js
- /Users/a.blackoff/Project/thesollution/thesollution/node_modules/nx/src/cli/init-local.js
- /Users/a.blackoff/Project/thesollution/thesollution/node_modules/nx/bin/nx.js
- /usr/local/lib/node_modules/nx/bin/nx.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (/Users/a.blackoff/Project/thesollution/thesollution/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at getRunner (/Users/a.blackoff/Project/thesollution/thesollution/node_modules/@nrwl/workspace/src/tasks-runner/run-command.js:298:27)
    at /Users/a.blackoff/Project/thesollution/thesollution/node_modules/@nrwl/workspace/src/tasks-runner/run-command.js:67:48
    at Generator.next (<anonymous>)
    at /Users/a.blackoff/Project/thesollution/thesollution/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at __awaiter (/Users/a.blackoff/Project/thesollution/thesollution/node_modules/tslib/tslib.js:113:16) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/a.blackoff/Project/thesollution/thesollution/node_modules/@nrwl/workspace/src/tasks-runner/run-command.js',
    '/Users/a.blackoff/Project/thesollution/thesollution/node_modules/@nrwl/workspace/src/command-line/run-one.js',
    '/Users/a.blackoff/Project/thesollution/thesollution/node_modules/nx/src/cli/init-local.js',
    '/Users/a.blackoff/Project/thesollution/thesollution/node_modules/nx/bin/nx.js',
    '/usr/local/lib/node_modules/nx/bin/nx.js'
  ]
}

As I understand it, the path to TaskRunner has changed.

This can be viewed in the migration: https://github.com/nrwl/nx/blob/master/packages/workspace/src/migrations/update-13-10-0/update-tasks-runner.ts

copy plugin constructs an incorrect destination path and fails to copy the file there

encountered a weird bug, where the file name of the destination path is removed from the constructed path.

plugin setup:

copyPlugin({
	resolveFrom: 'cwd',
	assets: [{
		from: 'public/**/*.json',
		to: 'dist/'
	}],
	verbose: true,
	copyOnStart: true,
	watch: true,
}),

cwd is in D:\GIT\myapp\
esbuild version: 0.17.10
copy plugin version: 2.1.0

output log:

i File copied: D:\GIT\myapp\public\collections\config.json -> D:\GIT\myapp\dist\collections\config.json
i File copied: D:\GIT\myapp\public\collections\config.schema.json -> D:\GIT\myapp\dist\collections\config.schema.json
i File copied: D:\GIT\myapp\public\collections\editor.json -> D:\GIT\myapp\dist\collections\editor.json
X [ERROR] EPERM: operation not permitted, copyfile 'D:\GIT\myapp\public\collections\publication-type.json' -> 'D:\GIT\myapp\dist\collections' [plugin plugin:copy]

    node_modules/esbuild/lib/main.js:1334:4:
      1334 │     await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
           ╵     ^

    at Object.copyFileSync (node:fs:2817:3)
    at copyOperationHandler (file:///D:/GIT/myapp/node_modules/esbuild-plugin-copy/dist/index.mjs:60:26)
    at file:///D:/GIT/myapp/node_modules/esbuild-plugin-copy/dist/index.mjs:122:17
    at Array.forEach (<anonymous>)
    at executor (file:///D:/GIT/myapp/node_modules/esbuild-plugin-copy/dist/index.mjs:121:18)
    at file:///D:/GIT/myapp/node_modules/esbuild-plugin-copy/dist/index.mjs:143:13
    at async D:\GIT\myapp\node_modules\esbuild\lib\main.js:1336:22
    at async Promise.all (index 0)
    at async requestCallbacks.on-start (D:\GIT\myapp\node_modules\esbuild\lib\main.js:1334:5)
    at async handleRequest (D:\GIT\myapp\node_modules\esbuild\lib\main.js:723:13)

esbuild running in watch mode produces the same output
source files are readable, destionation folder is clean, and writeable.

Tried to rename the publication-type.json json to something completely different, then it errors with a different file named publication.json. I dont know if filenames are relevant or not. My public folder contains these files:

assets\bootstrap.min.css
assets\forest.jpg
assets\react-dom.development.js
assets\react-dom.production.min.js
assets\react.development.js
assets\react.production.min.js
collections\charts.json
collections\config.json
collections\config.schema.json
collections\editor.json
collections\publication-type.json
collections\publication.json
collections\publication.ui.json
collections\UISchema\editor-UISchema.json
index.html

this plugin seems great and does exactly what we need, so I would be happy if this could be fixed!

esbuild-plugin-copy Could not resolve dependency

I get the following error when i try to install this package

npm install esbuild-plugin-copy --save-dev 
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/esbuild
npm ERR!   dev esbuild@"^0.15.10" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer esbuild@"^0.14.0" from [email protected]
npm ERR! node_modules/esbuild-plugin-copy
npm ERR!   dev esbuild-plugin-copy@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/kay/.npm/eresolve-report.txt for a full report.

Cannot find module '@nrwl/workspace/src/command-line/report'

I'm getting this when running yarn nx generate nx-plugin-esbuild:node-init few --no-interactive --dry-run:

Cannot find module '@nrwl/workspace/src/command-line/report'Cannot find module '@nrwl/workspace/src/command-line/report'
Require stack:
- ~/app/node_modules/nx-plugin-devkit/src/lib/executor-utils/info.js
- ~/app/node_modules/nx-plugin-devkit/src/index.js
- ~/app/node_modules/nx-plugin-esbuild/src/generators/node-init/normalize-schema.js
- ~/app/node_modules/nx-plugin-esbuild/src/generators/node-init/generator.js
- ~/app/node_modules/nx/src/config/workspaces.js
- ~/app/node_modules/nx/src/command-line/generate.js
- ~/app/node_modules/nx/src/command-line/nx-commands.js
- ~/app/node_modules/nx/bin/init-local.js
- ~/app/node_modules/nx/bin/nx.js'fewefw Cannot find module '@nrwl/workspace/src/command-line/report'

I'm using nx: 14.1.4 and @nrwl/workspace:14.1.5.

Cannot use glob pattern with wildcard in the middle of the path.

This pattern work

copy({
  resolveFrom: 'cwd',
  assets: {
    from: [
       '../../../../node_modules/my-package/build/assets/**/*',
    ],
    to: ['./build/assets'],
  }
})

But this doesn't

copy({
  resolveFrom: 'cwd',
  assets: {
    from: [
       '../../../../node_modules/**/build/assets/**/*',
    ],
    to: ['./build/assets'],
  }
})

And throws me a weird error...

i Resolve assert pair to path from: /workdir/packages/myproject/backends/standalone
i Watching mode enabled for all asset pairs, you can disable it by set watch to false in specified asset pairs
i Watching mode disabled. You need to enable build.watch option for watch mode to work.
✘ [ERROR] Cannot read properties of undefined (reading 'slice') [plugin plugin:copy]
    /workdir/node_modules/esbuild-plugin-copy/dist/index.js:84:28:
      84 │       preservedDirStructure.slice(1)
         ╵                             ^
    at copyOperationHandler (/workdir/node_modules/esbuild-plugin-copy/dist/index.js:84:29)
    at /workdir/node_modules/esbuild-plugin-copy/dist/index.js:152:17
    at Array.forEach (<anonymous>)
    at executor (/workdir/node_modules/esbuild-plugin-copy/dist/index.js:151:18)
    at /workdir/node_modules/esbuild-plugin-copy/dist/index.js:173:13
    at async /workdir/node_modules/esbuild/lib/main.js:1494:27
  This error came from the "onEnd" callback registered here:
    /workdir/node_modules/esbuild-plugin-copy/dist/index.js:106:22:
      106 │       build[applyHook](async () => {
          ╵                       ^
    at setup (/workdir/node_modules/esbuild-plugin-copy/dist/index.js:106:23)
    at handlePlugins (/workdir/node_modules/esbuild/lib/main.js:1292:21)
    at buildOrContextImpl (/workdir/node_modules/esbuild/lib/main.js:978:5)
    at Object.buildOrContext (/workdir/node_modules/esbuild/lib/main.js:786:5)
    at /workdir/node_modules/esbuild/lib/main.js:2196:68
    at new Promise (<anonymous>)
    at Object.context (/workdir/node_modules/esbuild/lib/main.js:2196:27)
    at Object.context (/workdir/node_modules/esbuild/lib/main.js:2036:58)
    at build (/workdir/packages/myproject/backends/standalone/build.js:16:33)
/workdir/node_modules/esbuild/lib/main.js:1649
  let error = new Error(text);
              ^
Error: Build failed with 1 error:
/workdir/node_modules/esbuild-plugin-copy/dist/index.js:84:28: ERROR: [plugin: plugin:copy] Cannot read properties of undefined (reading 'slice')
    at failureErrorWithLog (/workdir/node_modules/esbuild/lib/main.js:1649:15)
    at /workdir/node_modules/esbuild/lib/main.js:1058:25
    at /workdir/node_modules/esbuild/lib/main.js:1525:9 {
  errors: [Getter/Setter],
  warnings: [Getter/Setter]
}

Cannot use import statement outside a module

Hi. Please accept my apologies beforehand, for my lack of knowledge and experience.

I'm trying to use the esbuild-plugin-copy plugin, to copy several files to their final destinations, after esbuild has done its thing. For that purpose I have a simple build.js script, which I execute from my equally simple package.json like so:

"scripts": { "build": "node --trace-warnings build.js" }.

The build.js script itself roughly looks like this:

import copy from 'esbuild-plugin-copy';

require('esbuild').build({
    entryPoints: [
        ...
    ],
    loader: {
        ...
    },
    bundle: true,
    outdir: 'dist',
    plugins: [
        copy({
            assets: {
                from: ['./dist/*.js'],
                to: ['../assets/js'],
            },
        }),
        copy({
            assets: {
                from: ['./dist/*.css'],
                to: ['../assets/css'],
            },
        })
    ]
}).catch(() => process.exit(1))

Without the import and plugins sections, the script runs fine and produces the desired output files. However, when including the import and plugins sections, I get the following error:

import copy from 'esbuild-plugin-copy';
^^^^^^

SyntaxError: Cannot use import statement outside a module

My extremely limited knowledge tells me I'm mixing CommonJS and ES6 modules here. The problem is I don't know how to fix it. I have tried var copy = require('esbuild-plugin-copy'), but that does not work.

How can I get the copy function to work in my build script?

Feature request: Copy individual file to different filename

I am trying to move from webpack-copy-plugin to esbuild-plugin-copy.

However one of the things that currently doesn't seem supported is copying a file from for example hello.txt to world.txt. It instead creates a world.txt directory.

Ports from vite.config file should be respected

Hi, thanks for the package, it worked greatly so far. I have only one issue with currently enforced port 3000.

Currently the execution script forces a static port from the project.json file. I have a special case where the port is given dynamically from the environment. Why force the port in the project.json file, if it can be set statically as well directly on vite.config.ts file?

The given snippet works fine, and respects the ports from vite.config.ts file, also keeping the default port 3000 from vite if no port is given (and trying different ones if the 3000 is taken):

const { root, configFile } = schema;

  const serverFactory = await createServer({
    root,
    configFile, //remove server config, and let vite.config.ts define it
  });

  consola.info(chalk.cyan('Nx-Vite [Start] Starting \n'));

  const devServer = await serverFactory.listen(); //remove port here

  consola.success(
    `Vite server ready at ${chalk.green(
      `${https ? 'https:' : 'http:'}//localhost:${devServer.config.server.port}` //display the port actually used by the dev server
    )}`
  );

If you agree, I can make a PR

[plugin fileSize] Unexpected token: punc (.)

Hi, I wanted to add esbuild-plugin-filesize to my current project and got following error:

✘ [ERROR] [plugin fileSize] Unexpected token: punc (.)

    /opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:554:10:
      554 │     throw new JS_Parse_Error(message, filename, line, col, pos);
          ╵           ^

    at js_error (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:554:11)
    at croak (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:1278:9)
    at token_error (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:1286:9)
    at unexpected (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:1292:9)
    at statement (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:1418:17)
    at _embed_tokens_wrapper (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:1343:26)
    at parse_toplevel (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:3503:23)
    at parse (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:3516:7)
    at Object.minify (/opt/git/deusprox/openShare/research/node_modules/terser/dist/bundle.min.js:29472:42)
    at handleFileSizeDisplay (/opt/git/deusprox/openShare/research/node_modules/esbuild-plugin-filesize/src/lib/esbuild-plugin-filesize.js:21:57)

  This error came from the "onEnd" callback registered here:

    /opt/git/deusprox/openShare/research/node_modules/esbuild-plugin-filesize/src/lib/esbuild-plugin-filesize.js:38:12:
      38 │             onEnd(async () => {
         ╵             ~~~~~

    at setup (/opt/git/deusprox/openShare/research/node_modules/esbuild-plugin-filesize/src/lib/esbuild-plugin-filesize.js:38:13)
    at handlePlugins (/opt/git/deusprox/openShare/research/node_modules/esbuild/lib/main.js:852:23)

1 error

The issue terser/terser#1139 could be related since I am using optional chaining in this project, but @jridgewell mentioned this is supported since version v5.2.0 in that issue and this plugin already uses 5.7.0.

Using:

  • Node v16.13.2
  • esbuild 0.14.51
  • esbuild-plugin-filesize 0.3.0

[esbuild-plugin-copy] Copy `to` path not working as expected

I am trying to copy some assets files from an npm package into ./dist/assets

import { build } from 'esbuild';
import { copy } from 'esbuild-plugin-copy';

await build({
  entryPoints: ['./src/index.ts'],
  bundle: true,
  format: 'esm',
  outfile: './dist/index.js',
  plugins: [
    copy({
      verbose: true,
      resolveFrom: 'out',
      assets: [
        {
          from: './node_modules/some-package/dist/esm/*.worker*.js',
          to: './assets/' // still copies files into ./dist
        }
      ]
    })
  ],
}).catch(() => process.exit(1));

Instead of copying to ./dist/assets it copies to ./dist. Here is the verbose output:

i Resolve assert pair to path from: /Users/.../esbuild/dist

i Use Merge-Structure for current assets pair.
i File copied: /Users/.../dist/esm/format.worker-28fe4aab.js -> /Users/.../esbuild/dist/format.worker-28fe4aab.js
i File copied: /Users/.../dist/esm/format.worker-51010d22.js -> /Users/.../esbuild/dist/format.worker-51010d22.js

If I try to use to: './dist/assets' it copies to ./dist/dist instead.

i Resolve assert pair to path from: /Users/.../esbuild/dist

i Use Merge-Structure for current assets pair.
i File copied: /Users/.../dist/esm/format.worker-28fe4aab.js -> /Users/.../esbuild/dist/dist/format.worker-28fe4aab.js
i File copied: /Users/.../dist/esm/format.worker-51010d22.js -> /Users/.../esbuild/dist/dist/format.worker-51010d22.js

I have no idea what's happening...

Destination directory is not recursively created if 'to' asset path is not a directory

I have an asset that looks like this:
{
from: '/home/kkoukiou/repos/cockpit/node_modules/@patternfly/patternfly/assets/fonts/RedHatFont-updated/RedHatText/RedHatText-updated-Bold.woff2',
to: '/home/kkoukiou/repos/cockpit/dist/static/fonts/RedHatText-Bold.woff2'",
}

The ./dist/static/fonts directory does not exist and therefore the plugin fails with: text: "ENOENT: no such file or directory, copyfile ...

If I use directory for the 'to' path it works, but I need to rename the asset so this is not a solution.

I believe this conditional directory creation could be removed

[plugin plugin:compress] outputFiles is not iterable

Just trying the compress plugin and always receiving the same message:

const compress = require('esbuild-plugin-compress').compress

require('esbuild').build({
  entryPoints: ['./src/index.ts'],
  bundle: true,
  platform: 'node',
  outfile: './build/index.js',
  plugins: [
    compress({
      outputDir: 'dist',
    }),
  ],
}).catch(() => process.exit(1));
    ✘ [ERROR] [plugin plugin:compress] outputFiles is not iterable

    /Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild-plugin-compress/src/lib/esbuild-plugin-compress.js:48:67:
      48 │                 for (const { path: originOutputPath, contents } of outputFiles) {
         ╵                                                                    ^

    at /Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild-plugin-compress/src/lib/esbuild-plugin-compress.js:48:68
    at /Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:1040:21
    at runOnEndCallbacks (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:1045:11)
    at buildResponseToResult (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:1249:7)
    at /Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:1358:14
    at /Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:666:9
    at handleIncomingPacket (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:763:9)
    at Socket.readFromStdout (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:632:7)
    at Socket.emit (events.js:400:28)
    at addChunk (internal/streams/readable.js:293:12)

  This error came from the "onEnd" callback registered here:

    /Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild-plugin-compress/src/lib/esbuild-plugin-compress.js:47:12:
      47 │             onEnd(async ({ outputFiles }) => {
         ╵             ~~~~~

    at setup (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild-plugin-compress/src/lib/esbuild-plugin-compress.js:47:13)
    at handlePlugins (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:843:23)
    at Object.buildOrServe (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:1137:7)
    at /Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:2085:17
    at new Promise (<anonymous>)
    at Object.build (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:2084:14)
    at Object.build (/Users/renan/Projetos/tunnelhub/templates/template-delta/node_modules/esbuild/lib/main.js:1931:51)
    at Object.<anonymous> (/Users/renan/Projetos/tunnelhub/templates/template-delta/esbuild.js:6:20)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)

Using:

  • Node v14.18.3
  • esbuild 0.14.49
  • esbuild-plugin-compress: 0.3.0

esbuild-plugin-copy v1.6.0?

We recently tried to upgrade esbuild-plugin-copy to 1.5.2 and were running into some problems with our builds. Interestingly, I see that last night 1.6.0 was published on npm. I can't find the changelog anywhere, nor the release tag here, nor any files updated.

Am I confused about who is publishing the plugin now?

E2E: e2e project does not work with vite-plugin

Hi! I'm using the vite plugin with my react app. I think the problem is that the e2e tests doesn't start until the vite serve command finishes, but that command never finishes

// e2e project.json
"e2e": {
  "executor": "@nrwl/cypress:cypress",
  "options": {
    "cypressConfig": "apps/e2e/[name]/cypress.json",
    "devServerTarget": "[name]:serve",
    "headed": true
  },
  "configurations": {
    "production": {
      "devServerTarget": "[name]:serve:production"
    }
  }
}
// app project.json
"serve": {
  "executor": "nx-plugin-vite:serve",
  "options": {
    "configFile": "apps/[name]/vite.config.ts",
    "port": 3000,
    "host": true,
    "https": false,
    "root": "apps/[name]"
  }
}

Error:

[ vincent@PC ] :: 21:27:24 >> Codebase.js λ nx e2e thunder-e2e

> nx run thunder-e2e:e2e

i Nx-Vite [Start] Starting 

√ Vite server ready at http://localhost:3000

# nothing happens here... No test results or anything

Importing library from vite react app not working

Describe the bug
when i try to import a library in the nx repo (from /libs dir) it says the file does not exist. I imported it with compilerOptions.paths but i've also tried normal import (../../../libs/library).

To Reproduce
Steps to reproduce the behavior:

create a nx monorepo with create-nx-workspace

create a vite react app with this plugin

create a react library with the standart @nrwl/react command

import it to the vite app

Expected behavior

That the lib does import and will work as expected

To redroduce
I have this repo here: https://github.com/VincentThomas06/issue-vite

Copy fails after first from

I have a very simple setup with copy. I just want to copy 2 files into a folder.

copy({
    assets: {
        from: [
            "node_modules/jquery/dist/jquery.min.js",
            "node_modules/what-input/dist/what-input.min.js"
        ],
        to: [ "js/vendor" ]
    },
})

However, it always fails when processing the 2nd file. If I switch the order of the files, it still fails on the 2nd one. I did a verbose output and got this.

i Resolve assert pair to path from: /Users/joeworkman/Developer/proton-sites-template/dist/assets
i Watching mode disabled. You need to enable build.watch option for watch mode to work.
i The from path node_modules/jquery/dist/jquery.min.js,node_modules/what-input/dist/what-input.min.js of current asset pair doesnot ends with /**/*(.ext), 
i File copied: /Users/joeworkman/Developer/proton-sites-template/node_modules/jquery/dist/jquery.min.js -> /Users/joeworkman/Developer/proton-sites-template/dist/assets/js/vendor/jquery.min.js
i The from path node_modules/jquery/dist/jquery.min.js,node_modules/what-input/dist/what-input.min.js of current asset pair doesnot ends with /**/*(.ext), 
ERR > /Users/joeworkman/Developer/proton-sites-template/node_modules/esbuild/lib/main.js:1649
  let error = new Error(text);
              ^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.