使返回该目录在 Windows 上不被识别为内部或外部命令

使返回该目录在 Windows 上不被识别为内部或外部命令

我有一个使用 make 的项目,通常在 GNU/Linux 上运行,现在我尝试在 Windows 上运行它并出现错误(来自 git bash):

'.' is not recognized as an internal or external command,

我删除了 node_modules 之前的点,然后出现错误,提示 node_modules 无法识别。当我运行 npm install 时,node_modules 在我的目录中创建。

我尝试过 MinGW 和 GNUWin 版本的 make,但都返回相同的错误,大约一年前我在 Windows 上上次运行该项目时,该项目还在运行。

这是我的失败的 makefile:

VERSION=1.16.1
SED=sed
CD=cd
NPM=npm
CP=cp
RM=rm
CAT=cat
DATE=`date -uR`
GIT=git
BRANCH=`git branch | grep '^*' | sed 's/* //'`
ESLINT=node_modules/.bin/eslint
UGLIFY=node_modules/.bin/uglifyjs
JSONLINT=node_modules/.bin/jsonlint
JEST=node_modules/.bin/jest
CSSNANO=./node_modules/.bin/cssnano
SPEC_CHECKSUM=`md5sum __tests__/terminalSpec.js | cut -d' ' -f 1`
COMMIT=`git log -n 1 | grep commit | sed 's/commit //'`
URL=`git config --get remote.origin.url`
skip_re="[xfi]it\\(|[fdx]describe\\("

.PHONY: coverage test coveralls lint.src eslint skipped_tests jsonlint publish lint

ALL: Makefile .$(VERSION) terminal.jquery.json bower.json package.json js/jquery.terminal-$(VERSION).js js/jquery.terminal.js js/jquery.terminal-$(VERSION).min.js js/jquery.terminal.min.js css/jquery.terminal-$(VERSION).css css/jquery.terminal-$(VERSION).min.css css/jquery.terminal.min.css css/jquery.terminal.css README.md import.html js/terminal.widget.js www/Makefile

foo:
    echo `pwd`

bower.json: templates/bower.in .$(VERSION)
    $(SED) -e "s/{{VER}}/$(VERSION)/g" templates/bower.in > bower.json

package.json: templates/package.in .$(VERSION)
    $(SED) -e "s/{{VER}}/$(VERSION)/g" templates/package.in > package.json

js/jquery.terminal-$(VERSION).js: js/jquery.terminal-src.js .$(VERSION)
    $(GIT) branch | grep '* devel' > /dev/null && $(SED) -e "s/{{VER}}/DEV/g" -e "s/{{DATE}}/$(DATE)/g" js/jquery.terminal-src.js > js/jquery.terminal-$(VERSION).js || $(SED) -e "s/{{VER}}/$(VERSION)/g" -e "s/{{DATE}}/$(DATE)/g" js/jquery.terminal-src.js > js/jquery.terminal-$(VERSION).js

js/jquery.terminal.js: js/jquery.terminal-$(VERSION).js
    $(CP) js/jquery.terminal-$(VERSION).js js/jquery.terminal.js

js/jquery.terminal-$(VERSION).min.js: js/jquery.terminal-$(VERSION).js
    $(UGLIFY) -o js/jquery.terminal-$(VERSION).min.js --comments --mangle -- js/jquery.terminal-$(VERSION).js

js/jquery.terminal.min.js: js/jquery.terminal-$(VERSION).min.js
    $(CP) js/jquery.terminal-$(VERSION).min.js js/jquery.terminal.min.js

css/jquery.terminal-$(VERSION).css: css/jquery.terminal-src.css .$(VERSION)
    $(GIT) branch | grep '* devel' > /dev/null && $(SED) -e "s/{{VER}}/DEV/g" -e "s/{{DATE}}/$(DATE)/g" css/jquery.terminal-src.css > css/jquery.terminal-$(VERSION).css || $(SED) -e "s/{{VER}}/$(VERSION)/g" -e "s/{{DATE}}/$(DATE)/g" css/jquery.terminal-src.css > css/jquery.terminal-$(VERSION).css

css/jquery.terminal.css: css/jquery.terminal-$(VERSION).css .$(VERSION)
    $(CP) css/jquery.terminal-$(VERSION).css css/jquery.terminal.css

css/jquery.terminal.min.css: css/jquery.terminal-$(VERSION).min.css
    $(CP) css/jquery.terminal-$(VERSION).min.css css/jquery.terminal.min.css

css/jquery.terminal-$(VERSION).min.css: css/jquery.terminal-$(VERSION).css
    $(CSSNANO) css/jquery.terminal-$(VERSION).css css/jquery.terminal-$(VERSION).min.css --no-discardUnused --safe

README.md: templates/README.in .$(VERSION)
    $(GIT) branch | grep '* devel' > /dev/null && $(SED) -e "s/{{VER}}/DEV/g" -e \
    "s/{{BRANCH}}/$(BRANCH)/g" -e "s/{{CHECKSUM}}/$(SPEC_CHECKSUM)/" \
    -e "s/{{COMMIT}}/$(COMMIT)/g" < templates/README.in > README.md || $(SED) -e \
    "s/{{VER}}/$(VERSION)/g" -e "s/{{BRANCH}}/$(BRANCH)/g" -e \
    "s/{{CHECKSUM}}/$(SPEC_CHECKSUM)/" -e "s/{{COMMIT}}/$(COMMIT)/g" < templates/README.in > README.md

.$(VERSION): Makefile
    touch .$(VERSION)

Makefile: templates/Makefile.in
    $(SED) -e "s/{{VER""SION}}/"$(VERSION)"/" templates/Makefile.in > Makefile

import.html: templates/import.in
    $(SED) -e "s/{{BRANCH}}/$(BRANCH)/g" templates/import.in > import.html

js/terminal.widget.js: js/terminal.widget.in
    $(GIT) branch | grep '* devel' > /dev/null || $(SED) -e "s/{{VER}}/$(VERSION)/g" js/terminal.widget.in > js/terminal.widget.js

terminal.jquery.json: manifest .$(VERSION)
    $(SED) -e "s/{{VER}}/$(VERSION)/g" manifest > terminal.jquery.json

www/Makefile: $(wildcard www/Makefile.in) Makefile .$(VERSION)
    @test "$(BRANCH)" = "master" -a -d www && $(SED) -e "s/{{VER""SION}}/$(VERSION)/g" www/Makefile.in > www/Makefile || true

test:
    $(JEST) --coverage --collectCoverageFrom=js/{unix_formatting,jquery.terminal-src}.js

coveralls:
    $(CAT) ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

lint.src:
    $(ESLINT) js/jquery.terminal-src.js

eslint:
    $(ESLINT) js/jquery.terminal-src.js
    $(ESLINT) js/dterm.js
    $(ESLINT) js/xml_formatting.js
    $(ESLINT) js/unix_formatting.js
    $(ESLINT) js/prims.js
    $(ESLINT) js/less.js

skipped_tests:
    @! grep -E $(skip_re) __tests__/terminalSpec.js

jsonlint: package.json bower.json
    $(JSONLINT) package.json > /dev/null
    $(JSONLINT) bower.json > /dev/null

publish:
    $(GIT) clone $(URL) --depth 1 npm
    $(CD) npm && $(NPM) publish
    $(RM) -rf npm

lint: eslint jsonlint

使 foo 返回正确的目录。

问题在于这条规则:

UGLIFY=./node_modules/.bin/uglifyjs

js/jquery.terminal-$(VERSION).min.js: js/jquery.terminal-$(VERSION).js
    $(UGLIFY) -o js/jquery.terminal-$(VERSION).min.js --comments --mangle -- js/jquery.terminal-$(VERSION).js

但是当我在 gitbash 中从同一目录运行命令时,它运行成功,我也尝试在运行 make 之前运行 export PATH=.:$PATH 但出现了同样的错误。

我也尝试将 Makefile 的行尾从 unix 更改为 windows,但这也未能解决问题。

答案1

问题在于斜线与反斜线。因此解决方案是针对 Windows 和 Linux 使用不同的路径:

ifdef SYSTEMROOT
  UGLIFY=.\node_modules\.bin\uglifyjs
  JSONLINT=.\node_modules\.bin\jsonlint
  JEST=.\node_modules\.bin\jest
  CSSNANO=.\node_modules\.bin\cssnano
  ESLINT=.\node_modules\.bin\eslint
else
  UGLIFY=./node_modules/.bin/uglifyjs
  JSONLINT=./node_modules/.bin/jsonlint
  JEST=./node_modules/.bin/jest
  CSSNANO=./node_modules/.bin/cssnano
  ESLINT=./node_modules/.bin/eslint
endif

相关内容