diff --git a/package.json b/package.json index 9c2769c63..7efe8b34f 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "build-clean-all": "rimraf ./packages/*/build ./packages/*/tsconfig.tsbuildinfo", "watch": "node ./scripts/watch.js", "test": "jest", - "test:ci:unit": "jest packages --ci --coverage", + "test:ci:unit": "jest packages scripts --ci --coverage", "test:ci:e2e": "jest e2e --ci -i", "lint": "eslint --ext .js,.ts . --cache --report-unused-disable-directives", "postinstall": "yarn build", diff --git a/scripts/__tests__/build.test.js b/scripts/__tests__/build.test.js new file mode 100644 index 000000000..178849e41 --- /dev/null +++ b/scripts/__tests__/build.test.js @@ -0,0 +1,48 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +const {execFileSync} = require('child_process'); +const fs = require('fs'); +const path = require('path'); + +test('builds a package when its checkout path contains glob characters', () => { + const root = path.resolve(__dirname, '../..'); + const checkout = fs.mkdtempSync(path.join(root, 'build-(fixture)-')); + + try { + const scripts = path.join(checkout, 'scripts'); + fs.mkdirSync(scripts); + for (const file of ['build.js', 'helpers.js']) { + fs.copyFileSync( + path.join(root, 'scripts', file), + path.join(scripts, file), + ); + } + fs.copyFileSync( + path.join(root, 'babel.config.js'), + path.join(checkout, 'babel.config.js'), + ); + + const pkg = path.join(checkout, 'packages', 'example'); + const src = path.join(pkg, 'src'); + fs.mkdirSync(src, {recursive: true}); + fs.writeFileSync( + path.join(src, 'index.ts'), + 'export const value: number = 42;', + ); + + execFileSync(process.execPath, [path.join(scripts, 'build.js')], { + cwd: checkout, + }); + + expect( + fs.readFileSync(path.join(pkg, 'build', 'index.js'), 'utf8'), + ).toContain('const value = 42;'); + } finally { + fs.rmSync(checkout, {recursive: true, force: true}); + } +}); diff --git a/scripts/build.js b/scripts/build.js index 2f8e587f6..eed8db6c4 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -53,10 +53,9 @@ function getBuildPath(file, buildFolder) { } function buildNodePackage(p) { - const srcDir = path.resolve(p, SRC_DIR); - const pattern = path.resolve(srcDir, '**/*'); - const files = glob.sync(pattern, { - nodir: true, + const files = glob.sync('**/*', { + cwd: path.resolve(p, SRC_DIR), + absolute: true, }); process.stdout.write(adjustToTerminalWidth(`${path.basename(p)}\n`));