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

perl one-liners doing substitution with s|pattern|replacement| called from webpack.config.js apparently try to run "pattern" as a program #4949

Open
coderextreme opened this issue May 12, 2024 · 4 comments

Comments

@coderextreme
Copy link

coderextreme commented May 12, 2024

This is not a problem on WSL2 or MacOS apparently. This is just a heads up, as I'd like to do development under Git Bash, and it has this problem, with it's version of perl or webpack. I haven't tested another perl version that I know of. Nor have I tested perl outside of webpack.

things that fail might be:

`perl -p0e 's|\\/\\*.*?\\*\\/||sg' src/x_ite.css | npx sass --stdin --style compressed > dist/x_ite.css`,
`perl -p0i -e 's|^|/* X_ITE v'$npm_package_version' */|sg' dist/x_ite.css`,
`perl -p0i -e 's|".*?"|'\`npm pkg get version\`'|sg' src/x_ite/BROWSER_VERSION.js`,
`perl -p0i -e 's/export default (?:true|false);/export default false;/sg' src/x_ite/DEVELOPMENT.js`,
`perl -p0i -e 's|"X_ITE.X3D"|"X_ITE.X3D-'$npm_package_version'"|sg' dist/x_ite{,.min}.js`,
`perl -p0i -e 's|^(/\\*.*?\\*/)?\\s*|/* X_ITE v'$npm_package_version' */|sg' dist/x_ite{,.min}.js`,
`perl -p0i -e 's|sourceMappingURL=.*?\\.map||sg' dist/x_ite{,.min}.js`,
`perl -p0i -e 's/export default (?:true|false);/export default true;/sg' src/x_ite/DEVELOPMENT.js`,
`perl -p0i -e 's|".*?"|'\`npm pkg get version\`'|sg' src/x_ite/BROWSER_VERSION.js`,
`perl -p0i -e 's/export default (?:true|false);/export default false;/sg' src/x_ite/DEVELOPMENT.js`,
`perl -p0i -e 's|"X_ITE.X3D"|"X_ITE.X3D-'$npm_package_version'"|sg' dist/x_ite{,.min}.mjs`,
`perl -p0i -e 's|^(/\\*.*?\\*/)?\\s*|/* X_ITE v'$npm_package_version' */|sg' dist/x_ite{,.min}.mjs`,
`perl -p0i -e 's|sourceMappingURL=.*?\\.map||sg' dist/x_ite{,.min}.mjs`,
`perl -p0i -e 's/export default (?:true|false);/export default true;/sg' src/x_ite/DEVELOPMENT.js`,
`perl -p0i -e 's|"X_ITE.X3D"|"X_ITE.X3D-'$npm_package_version'"|sg' dist/assets/components/${name}{,.min}.js`,
`perl -p0i -e 's|^(/\\*.*?\\*/)?\\s*|/* X_ITE v'$npm_package_version' */|sg' dist/assets/components/${name}{,.min}.js`,
`perl -p0i -e 's|sourceMappingURL=.*?\\.map||sg' dist/assets/components/${name}{,.min}.js`,
`perl -p0i -e 's|("./index.js"\\).*?\\})|$1.bind({})|sg' dist/assets/components/${name}{,.min}.js`,
`perl -p0i -e 's/[,;]*(var\\s+)?(CharLS|OpenJPEG)\\s*=\\s*function/;module.exports=function/sg' dist/assets/components/${name}{,.min}.js`,

These are from X_ITE X3D Brower's webpack.config.js which is designed to run on macs. Note that even pattern alternation with | tries to run a program.

Again, this is not a show stopper, as I've moved development to WSL2, but WSL2 can't really use the Windows file system without upgrading the Linux kernel, which is at 5.15

Here's a typical webpack config example:

     new WebpackShellPluginNext ({
        logging: false,
        onBuildStart: {
           scripts: [
              `echo 'Bundling x_ite ...'`,
              `perl -p0e 's|\\/\\*.*?\\*\\/||sg' src/x_ite.css | npx sass --stdin --style compressed > dist/x_ite.css`,
              `perl -p0i -e 's|^|/* X_ITE v'$npm_package_version' */|sg' dist/x_ite.css`,
              `perl -p0i -e 's|".*?"|'\`npm pkg get version\`'|sg' src/x_ite/BROWSER_VERSION.js`,
              `perl -p0i -e 's/export default (?:true|false);/export default false;/sg' src/x_ite/DEVELOPMENT.js`,
           ],
           blocking: true,
           parallel: false,
        },
        onBuildEnd: {                                                                                                              scripts: [
              // Version
              `perl -p0i -e 's|"X_ITE.X3D"|"X_ITE.X3D-'$npm_package_version'"|sg' dist/x_ite{,.min}.js`,
              `perl -p0i -e 's|^(/\\*.*?\\*/)?\\s*|/* X_ITE v'$npm_package_version' */|sg' dist/x_ite{,.min}.js`,
              // Source Maps
              `perl -p0i -e 's|sourceMappingURL=.*?\\.map||sg' dist/x_ite{,.min}.js`,
              // Debug
              `perl -p0i -e 's/export default (?:true|false);/export default true;/sg' src/x_ite/DEVELOPMENT.js`,
              // Licenses
              `cp LICENSE.md dist/LICENSE.md`,
              `echo '\`\`\`' >> dist/LICENSE.md`,
              `touch dist/x_ite.min.js.LICENSE.txt`,
              `cat dist/x_ite.min.js.LICENSE.txt >> dist/LICENSE.md`,
              `rm dist/x_ite.min.js.LICENSE.txt`,
              `echo '\`\`\`' >> dist/LICENSE.md`,
           ],
           blocking: false,
           parallel: false,                                                                                                     },                                                                                                                  }),

I hope this gets fixed...

@rimrul
Copy link
Member

rimrul commented May 12, 2024

So these commands get called from javascript code, right? Presumably through nodejs? In that case where do you get that nodejs from and how does it execute these commands? If it's a native Windows nodejs I suspect that these get passed to cmd.exe (as opposed to any sort of POSIX-ish shell) which does not follow POSIX shell quoting rules. I don't think there is anything we can fix about that.

@coderextreme
Copy link
Author

coderextreme commented May 12, 2024 via email

@rimrul
Copy link
Member

rimrul commented May 12, 2024

The webpack installation guide starts with starts with

Before we begin, make sure you have a fresh version of Node.js installed. The current Long Term Support (LTS) release is an ideal starting point.

So there's probably a node involved somewhere along the line.

This WebPackShellPluginNext thing uses exec/spawn and execSync/spawnSync to run those scripts. At that point node seems to pass on your commands to cmd.

@coderextreme
Copy link
Author

coderextreme commented May 12, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants