Skip to content

Make postinstall, predev and prebuild work with npm workspaces #147

@bbougon

Description

@bbougon

Context:
When using npm workspaces, i.e nested subprojects (see below) postinstall, predev and prebuild are not working as expected.

- project
   - sub-project-1 (React App)
   - sub-project-2 (NodeJs App)
   - sub-project-...

With npm workspaces, node_modules directories are created in root and sub projects and all dependencies are stored in node_modules root directory.
Therefore, postinstall, predev and prebuild need to know what is the targeted project directory (here sub-project-1 and / or what node_modules directory to use (i.e node_modules root directory).

Current behavior:

  • adding postinstall, predev and prebuild in sub-project-1 package.json return the following error:

    npm ERR! command failed
    npm ERR! command sh -c copy-dsfr-to-public
    npm ERR! node:fs:1593
    npm ERR!   handleErrorFromBinding(ctx);
    npm ERR!   ^
    npm ERR! 
    npm ERR! Error: ENOENT: no such file or directory, lstat '/Users/bertrandbougon/Projets/beta-gouv/mon-aide-cyber/mon-aide-cyber/mon-aide-cyber-ui/node_modules/@codegouvfr/react-dsfr/dsfr'
    npm ERR!     at lstatSync (node:fs:1593:3)
    npm ERR!     at statFunc (node:internal/fs/cp/cp-sync:122:15)
    npm ERR!     at getStatsSync (node:internal/fs/cp/cp-sync:123:19)
    npm ERR!     at checkPathsSync (node:internal/fs/cp/cp-sync:72:33)
    npm ERR!     at cpSyncFn (node:internal/fs/cp/cp-sync:58:42)
    npm ERR!     at Object.cpSync (node:fs:2932:3)
    npm ERR!     at /Users/bertrandbougon/Projets/beta-gouv/mon-aide-cyber/mon-aide-cyber/node_modules/@codegouvfr/react-dsfr/bin/copy-dsfr-to-public.js:213:20
    npm ERR!     at step (/Users/bertrandbougon/Projets/beta-gouv/mon-aide-cyber/mon-aide-cyber/node_modules/@codegouvfr/react-dsfr/bin/copy-dsfr-to-public.js:58:23)
    npm ERR!     at Object.next (/Users/bertrandbougon/Projets/beta-gouv/mon-aide-cyber/mon-aide-cyber/node_modules/@codegouvfr/react-dsfr/bin/copy-dsfr-to-public.js:39:53)
    npm ERR!     at fulfilled (/Users/bertrandbougon/Projets/beta-gouv/mon-aide-cyber/mon-aide-cyber/node_modules/@codegouvfr/react-dsfr/bin/copy-dsfr-to-public.js:30:58) {
    npm ERR!   errno: -2,
    npm ERR!   syscall: 'lstat',
    npm ERR!   code: 'ENOENT',
    npm ERR!   path: '/Users/bertrandbougon/Projets/beta-gouv/mon-aide-cyber/mon-aide-cyber/mon-aide-cyber-ui/node_modules/@codegouvfr/react-dsfr/dsfr'
    npm ERR! }
    npm ERR! 
    npm ERR! Node.js v18.16.1
    
  • adding postinstall, predev and prebuild in root directory package.json return the following error:

    > copy-dsfr-to-public
    
    There is no public/ directory in the current working directory, we don't know your framework you are not calling this script 
    at the right location or we don't know your React framework please submit an issue about it here 
    https:://github.com/codegouvfr/react-dsfr/issues
    npm ERR! code 255
    npm ERR! path /Users/bertrandbougon/Projets/beta-gouv/mon-aide-cyber/mon-aide-cyber
    npm ERR! command failed
    npm ERR! command sh -c copy-dsfr-to-public
    

Expected behavior:

  • add postinstall, predev and prebuild in sub-project-1 package.json
  • files are copied from root_directory/node_modules/@codegoufr/... to sub-project-1/public

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions