Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@nrwl/nx-plugin:plugin generator includes .ts files in dist #9283

Closed
michaelcamper opened this issue Mar 11, 2022 · 14 comments · Fixed by #9484
Closed

@nrwl/nx-plugin:plugin generator includes .ts files in dist #9283

michaelcamper opened this issue Mar 11, 2022 · 14 comments · Fixed by #9484

Comments

@michaelcamper
Copy link

michaelcamper commented Mar 11, 2022

Current Behavior

@nrwl/nx-plugin:plugin generator defines build executor (@nrwl/js:tsc) which still includes .ts files in build dist.

Expected Behavior

".ts" should not be included in build output

Steps to Reproduce

  • initialise new workspace: yarn create nx-workspace my-org --preset=core --no-nx-cloud
  • install "@nrwl/nx-plugin": yarn add -W -D @nrwl/nx-plugin
  • generate a new plugin: nx g @nrwl/nx-plugin:plugin my-plugin
  • build plugin: nx build my-plugin
  • check dist files

This issue seems to be related to the replacement of @nrwl/node:package to @nrwl/js:tsc executor.

This issue may not be prioritized if details are not provided to help us reproduce the issue.

Failure Logs

Environment

Node : 16.13.0
OS : darwin arm64
yarn : 1.22.17

nx : 13.8.7
@nrwl/angular : undefined
@nrwl/cli : 13.8.7
@nrwl/cypress : 13.8.7
@nrwl/detox : undefined
@nrwl/devkit : 13.8.7
@nrwl/eslint-plugin-nx : 13.8.7
@nrwl/express : undefined
@nrwl/jest : 13.8.7
@nrwl/js : 13.8.7
@nrwl/linter : 13.8.7
@nrwl/nest : undefined
@nrwl/next : undefined
@nrwl/node : 13.8.7
@nrwl/nx-cloud : undefined
@nrwl/react : 13.8.7
@nrwl/react-native : undefined
@nrwl/schematics : undefined
@nrwl/storybook : 13.8.7
@nrwl/tao : 13.8.7
@nrwl/web : 13.8.7
@nrwl/workspace : 13.8.7
typescript : 4.4.4
rxjs : 6.6.7

Community plugins:
@nrwl/nx-plugin: 13.8.7

@michaelcamper michaelcamper changed the title @nrwl/nx-plugin:plugin generator includes .ts in build executor @nrwl/nx-plugin:plugin generator includes .ts files in dist Mar 11, 2022
@AgentEnder AgentEnder self-assigned this Mar 11, 2022
@AgentEnder
Copy link
Member

Hey, I can't seem to reproduce this. To test I followed:

  1. npx create-nx-plugin test --pluginName my-plugin
  2. cd test
  3. nx build my-plugin

This resulted in the below dist contents for dist/packages/my-plugin:
image

There are some .d.ts files, but no raw .ts files. Is this different from your observations?

@michaelcamper
Copy link
Author

Wow, you guys are very quick to reply!

The issue does not occur when using the create-nx-plugin starter-kit as it's using version 13.2.3, where the @nrwl/node:package executor is still used for the build target.

However, when using create-nx-workspace starter-kit (which currently uses version 13.8.7 and @nrwl/js:tsc for the build target) and generating a plugin afterwards this behavior occurs.

I have updated the "steps to reproduce" in order to be more concise 😁

@michaelcamper
Copy link
Author

The issues seems to be caused by targets.build.options.assets[1] in the respective project.json:

...,
{
  "input": "./packages/my-plugin/src",
  "glob": "**/!(*.ts)",
  "output": "./src"
},
...

Adding "ignore": "**/*.ts" works as an ugly workaround

@AgentEnder
Copy link
Member

Double checking in my repo, my workspace is on 13.8.7. Are you on windows by chance?

@AgentEnder
Copy link
Member

Here is the project.json for the my-plugin project:

{
  "root": "packages/my-plugin",
  "sourceRoot": "packages/my-plugin/src",
  "targets": {
    "build": {
      "executor": "@nrwl/js:tsc",
      "outputs": ["{options.outputPath}"],
      "options": {
        "outputPath": "dist/packages/my-plugin",
        "main": "packages/my-plugin/src/index.ts",
        "tsConfig": "packages/my-plugin/tsconfig.lib.json",
        "assets": [
          "packages/my-plugin/*.md",
          {
            "input": "./packages/my-plugin/src",
            "glob": "**/!(*.ts)",
            "output": "./src"
          },
          {
            "input": "./packages/my-plugin/src",
            "glob": "**/*.d.ts",
            "output": "./src"
          },
          {
            "input": "./packages/my-plugin",
            "glob": "generators.json",
            "output": "."
          },
          {
            "input": "./packages/my-plugin",
            "glob": "executors.json",
            "output": "."
          }
        ]
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["packages/my-plugin/**/*.ts"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["coverage/packages/my-plugin"],
      "options": {
        "jestConfig": "packages/my-plugin/jest.config.js",
        "passWithNoTests": true
      }
    }
  },
  "tags": []
}

@michaelcamper
Copy link
Author

This is odd. No, I am on MacOS

This is my report after running the steps you provided:

 Node : 16.13.0
  OS   : darwin arm64
  yarn : 1.22.17
  
  nx : 13.2.3
  @nrwl/angular : undefined
  @nrwl/cli : 13.2.3
  @nrwl/cypress : undefined
  @nrwl/devkit : 13.2.3
  @nrwl/eslint-plugin-nx : 13.2.3
  @nrwl/express : undefined
  @nrwl/jest : 13.2.3
  @nrwl/linter : 13.2.3
  @nrwl/nest : undefined
  @nrwl/next : undefined
  @nrwl/node : 13.2.3
  @nrwl/nx-cloud : undefined
  @nrwl/react : undefined
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.2.3
  @nrwl/web : undefined
  @nrwl/workspace : 13.2.3
  @nrwl/storybook : undefined
  @nrwl/gatsby : undefined
  typescript : 4.4.4
  rxjs : 6.6.7
  ---------------------------------------
  Community plugins:
         @nrwl/nx-plugin: 13.2.3

@AgentEnder
Copy link
Member

npx caches packages sometimes. Try npx create-nx-plugin@latest

@boeto
Copy link

boeto commented Mar 12, 2022

@AgentEnder please using the yarn create nx-workspace my-org --preset=core --no-nx-cloud should be able to reproduce the issues instead of npx create-nx-plugin@latest

@boeto
Copy link

boeto commented Mar 12, 2022

The issues seems to be caused by targets.build.options.assets[1] in the respective project.json:

...,
{
  "input": "./packages/my-plugin/src",
  "glob": "**/!(*.ts)",
  "output": "./src"
},
...

Adding "ignore": "**/*.ts" works as an ugly workaround

This parameter !(*.ts) should not be parsed, so it should be

{
  "input": "./packages/my-plugin/src",
  "glob": "**/*",
  "ignore": ["**/*.ts"],
  "output": "./src"
},

@AgentEnder AgentEnder added blocked: retry with latest Retry with latest release or head. and removed blocked: retry with latest Retry with latest release or head. labels Mar 14, 2022
@AgentEnder
Copy link
Member

I just retried this with 13.8.8, with the below environment. I still can't reproduce this, as the only ts files in the build were .d.ts files, as expected. Can you provide a reproduction in the form of a repo I can clone and test?

 >  NX   Report complete - copy this into the issue template

   Node : 14.17.0
   OS   : darwin x64
   npm  : 6.14.13
   
   nx : undefined
   @nrwl/angular : undefined
   @nrwl/cli : 13.8.8
   @nrwl/cypress : undefined
   @nrwl/detox : undefined
   @nrwl/devkit : 13.8.8
   @nrwl/eslint-plugin-nx : 13.8.8
   @nrwl/express : undefined
   @nrwl/jest : 13.8.8
   @nrwl/js : 13.8.8
   @nrwl/linter : 13.8.8
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : undefined
   @nrwl/nx-cloud : undefined
   @nrwl/react : undefined
   @nrwl/react-native : undefined
   @nrwl/schematics : undefined
   @nrwl/storybook : undefined
   @nrwl/tao : 13.8.8
   @nrwl/web : undefined
   @nrwl/workspace : 13.8.8
   typescript : 4.5.5
   rxjs : 6.6.7
   ---------------------------------------
   Community plugins:
         @nrwl/nx-plugin: 13.8.8

@boeto
Copy link

boeto commented Mar 22, 2022

@AgentEnder I created the reproduction, please check it~

#!/bin/sh

# To test followed:
npx create-nx-plugin test-nx-plugin-build-yarn --pluginName my-plugin --package-manager=yarn
cd test-nx-plugin-build-yarn
yarn nx build my-plugin
ls dist/packages/my-plugin/src/generators/my-plugin
# files             generator.js      generator.spec.ts schema.d.ts
# generator.d.ts    generator.js.map  generator.ts      schema.json

#############################################################################

#Set yarn workspace followed:
yarn set version 3.2.0

cat <<EOF | tee .yarnrc.yml 
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.2.0.cjs
EOF

#Add .gitignore
cat <<EOF | tee -a .gitignore

# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions 
EOF

@gioragutt
Copy link
Contributor

@michaelcamper @boeto after some research the problem seems to be a regression of fast-glob, @AgentEnder found that 👍🏻

A workaround in the meanwhile, if you're using yarn, is to add the following to your package.json:

{
  "resolutions": {
    "fast-glob": "3.2.7"
  }
}

@AgentEnder
Copy link
Member

Thanks again @gioragutt! We found it together. We'll work on pinning the version for fast-glob in nx, until that goes through the npm overrides or yarn resolutions mechanisms should unblock yall. See here for the npm solution https://docs.npmjs.com/cli/v8/configuring-npm/package-json#overrides

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants