Skip to content

Commit

Permalink
Merge pull request #755 from aaron-prindle/invalid-package-json
Browse files Browse the repository at this point in the history
fixes issue where FTL node would succeed on invalid name in package.json
  • Loading branch information
aaron-prindle committed Jan 16, 2019
2 parents cfd5e1a + 2eb9531 commit 9a37aba
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ftl/integration_tests/ftl_node_integration_tests_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'destination_test', 'metadata_test', 'npmrc_test', 'file_test',
'empty_descriptor_test', 'no_descriptor_test',
'no_deps_test', 'additional_directory', 'function_to_app_test',
'yarn_test'
'yarn_test',
]

_TEST_DIR = '/workspace/ftl/node/testdata'
Expand Down
6 changes: 5 additions & 1 deletion ftl/node/layer_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _gen_yarn_install_tar(self, app_dir):

def _gen_npm_install_tar(self, app_dir):
npm_install_cmd = ['npm', 'install', '--production']
ftl_util.run_command(
npm_output = ftl_util.run_command(
'npm_install',
npm_install_cmd,
cmd_cwd=app_dir,
Expand All @@ -122,6 +122,10 @@ def _gen_npm_install_tar(self, app_dir):
module_destination = os.path.join(self._destination_path,
'node_modules')
modules_dir = os.path.join(self._directory, "node_modules")
if not os.path.isdir(modules_dir) or os.listdir(modules_dir) == []:
if "Invalid name" in npm_output:
raise ftl_error.UserError("%s\n%s" % (npm_output, "0"))

return ftl_util.zip_dir_to_layer_sha(modules_dir, module_destination)

def _log_cache_result(self, hit, key):
Expand Down
12 changes: 12 additions & 0 deletions ftl/node/testdata/invalid_package_test/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var express = require('express');
var app = express();

// Routes
app.get('/', function(req, res) {
res.send('Hello World!');
});

// Listen
var port = process.env.PORT || 3000;
app.listen(port);
console.log('Listening on localhost:'+ port);
Empty file.
8 changes: 8 additions & 0 deletions ftl/node/testdata/invalid_package_test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "Cloud Storage Upload/Download Timeout",
"version": "0.0.1",
"dependencies": {
"express": "3.x",
"@google-cloud/storage": "^1.7.0"
}
}
10 changes: 10 additions & 0 deletions ftl/node/testdata/invalid_package_test/structure_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
schemaVersion: '2.0.0'
fileExistenceTests:
- name: 'express dependency'
path: '/srv/node_modules/express'
shouldExist: true
isDirectory: true
- name: 'package devdependency'
path: '/srv/node_modules/package'
shouldExist: false
isDirectory: true

0 comments on commit 9a37aba

Please sign in to comment.