ampproject / amp-toolbox

A collection of AMP tools making it easier to publish and host AMP pages.
Apache License 2.0
450 stars 242 forks source link

amp-toolbox does not build on Windows #668

Open mdmower opened 4 years ago

mdmower commented 4 years ago

Windows 10 64bit (Version 1909) node.js 12.16.0 npm 6.13.4

npm run build

lerna ERR! npm run build exited 2 in '@ampproject/toolbox-linter'
lerna ERR! npm run build stdout:

> @ampproject/toolbox-linter@2.0.1 build C:\Users\mdmower\source\amp-toolbox\packages\linter
> tsc --resolveJsonModule --module commonjs --target es2018 --esModuleInterop --strictNullChecks --declaration --outDir dist src/*.ts

error TS6053: File 'src/*.ts' not found.

lerna ERR! npm run build stderr:
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! @ampproject/toolbox-linter@2.0.1 build: `tsc --resolveJsonModule --module commonjs --target es2018 --esModuleInterop --strictNullChecks --declaration --outDir dist src/*.ts`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the @ampproject/toolbox-linter@2.0.1 build script.
sebastianbenz commented 4 years ago

Is the / the problem here? I don't own a windows machine which makes it hard for me to test this. //cc @ithinkihaveacat

mdmower commented 4 years ago

Is the / the problem here? I don't own a windows machine which makes it hard for me to test this.

That's part of the problem. In general though, all npm scripts definitions in all package.json need to be written with cross-platform terminal commands (e.g. && and VARX=true somecmd are also *nix shell specific). gulp is often used for tasks like these (see amphtml project). A couple of other options are mentioned here: https://stackoverflow.com/questions/41548990/how-to-create-cross-platform-scripts-multiple-command-for-single-line-in-packa .

ithinkihaveacat commented 4 years ago

I think the problem here is that the Windows shell doesn't support globbing, so src/*.ts doesn't get expanded. Some tools seem to build support for this themselves (like eslint), but tsc does not.

The next easiest fix might be to use tsconfig.json to configure tsc instead of switches to configure tsc. There was a reason why I didn't do that in the first place but I can't remember why…

So amp-toolbox should support Windows? What are the options for testing on Windows, are there Windows machines we can ssh into or something?

andreban commented 4 years ago

The postinstall event for toolbox-optimizer fails on Windows too:

PS D:\Projects\amp-toolbox> npm i

> husky@4.2.5 install D:\Projects\amp-toolbox\node_modules\husky
> node husky install

husky > Setting up git hooks
husky > Done

> core-js@2.6.11 postinstall D:\Projects\amp-toolbox\node_modules\babel-runtime\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)

> core-js@3.6.4 postinstall D:\Projects\amp-toolbox\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"

> @ampproject/toolbox-optimizer@file:packages/optimizer postinstall D:\Projects\amp-toolbox\node_modules\@ampproject\toolbox-optimizer
> scripts/init.js

'scripts' is not recognized as an internal or external command,
operable program or batch file.
npm WARN rollback Rolling back postcss-selector-parser@3.1.2 failed (this is probably harmless): EPERM: operation not permitted, lstat 'D:\Projects\amp-toolbox\node_modules\postcss-minify-selectors\node_modules'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: google-closure-compiler-osx@20200406.0.0 (node_modules\google-closure-compiler-osx):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for google-closure-compiler-osx@20200406.0.0: wanted {"os":"darwin","arch":"x64,x86"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: google-closure-compiler-linux@20200406.0.0 (node_modules\google-closure-compiler-linux):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for google-closure-compiler-linux@20200406.0.0: wanted {"os":"linux","arch":"x64,x86"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ampproject/toolbox-optimizer@file:packages/optimizer postinstall: `scripts/init.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ampproject/toolbox-optimizer@file:packages/optimizer postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\andre\AppData\Roaming\npm-cache\_logs\2020-05-13T18_56_09_791Z-debug.log

The fix for this one is to explicitly invoking node when executing the script on package.json, as Windows won't understand shebangs:

...
  "scripts": {
    "postinstall": "node scripts/init.js"
  },
...

@ithinkihaveacat I've been using tsconfig.json in Bubblewrap modules without issues. Curious on what was the reason you didn't.