From 25dea6a1364a9e7aab59171aed7795e5f55fd8c9 Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Mon, 25 Apr 2016 15:06:37 -0700 Subject: [PATCH] feat(package): require `'engines': {'nylas': '*'}` in package.json --- build/resources/nylas | 2 +- build/tasks/add-nylas-build-resources-task.coffee | 11 +---------- internal_packages/screenshot-mode/package.json | 3 +++ src/package-manager.coffee | 13 ++++++++++--- src/package.coffee | 2 ++ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/build/resources/nylas b/build/resources/nylas index ae4de39d2..7bcb19180 160000 --- a/build/resources/nylas +++ b/build/resources/nylas @@ -1 +1 @@ -Subproject commit ae4de39d22e1f0c85641a988dc21ec44846884ef +Subproject commit 7bcb1918054cad23fd217dff38df6596b52ee87b diff --git a/build/tasks/add-nylas-build-resources-task.coffee b/build/tasks/add-nylas-build-resources-task.coffee index e7422b7df..af9c27209 100644 --- a/build/tasks/add-nylas-build-resources-task.coffee +++ b/build/tasks/add-nylas-build-resources-task.coffee @@ -3,7 +3,7 @@ path = require 'path' module.exports = (grunt) -> {cp, mkdir, rm} = require('./task-helpers')(grunt) - rootDir = path.resolve(path.join('resources', 'nylas')) + rootDir = path.resolve(path.join('../', 'internal_packages', 'pro')) copyArcFiles = -> cp path.join(rootDir, 'arc-N1', '.arcconfig'), '.arcconfig' @@ -13,14 +13,6 @@ module.exports = (grunt) -> copySourceExtensions = -> cp path.join(rootDir, 'src'), 'src' - linkPlugins = -> - for plugin in fs.readdirSync(path.join(rootDir, 'packages')) - from = path.join(rootDir, 'packages', plugin) - to = path.join(path.resolve('internal_packages'), plugin) - if not fs.existsSync(to) - grunt.log.writeln "Adding '#{plugin}' to internal_packages" - fs.symlinkSync(from, to, 'dir') - desc = 'Adds in proprietary Nylas packages, fonts, and sounds to N1' grunt.registerTask 'add-nylas-build-resources', desc, -> canaryFileExists = fs.existsSync(path.join(rootDir, "README.md")) @@ -31,4 +23,3 @@ module.exports = (grunt) -> grunt.log.writeln "Found proprietary Nylas plugins" copyArcFiles() copySourceExtensions() - linkPlugins() diff --git a/internal_packages/screenshot-mode/package.json b/internal_packages/screenshot-mode/package.json index 862d5ef3d..83110e3ae 100755 --- a/internal_packages/screenshot-mode/package.json +++ b/internal_packages/screenshot-mode/package.json @@ -5,6 +5,9 @@ "description": "Replaces all text with blocks for taking screenshots without PII", "license": "Proprietary", "private": true, + "engines": { + "nylas": "*" + }, "windowTypes": { "all": true } diff --git a/src/package-manager.coffee b/src/package-manager.coffee index ca9464f92..8b78bf9f9 100644 --- a/src/package-manager.coffee +++ b/src/package-manager.coffee @@ -43,6 +43,7 @@ class PackageManager @packageDirPaths.push(path.join(@resourcePath, "spec", "fixtures", "packages")) else @packageDirPaths.push(path.join(@resourcePath, "internal_packages")) + @packageDirPaths.push(path.join(@resourcePath, "internal_packages", "pro")) if not safeMode if @devMode @packageDirPaths.push(path.join(configDirPath, "dev", "packages")) @@ -174,7 +175,7 @@ class PackageManager return packagePath if fs.isDirectorySync(packagePath) packagePath = path.join(@resourcePath, 'node_modules', name) - return packagePath if @nasNylasEngine(packagePath) + return packagePath if @hasNylasEngine(packagePath) # Public: Is the package with the given name bundled with Nylas? # @@ -313,7 +314,13 @@ class PackageManager if windowType packagePaths = _.filter packagePaths, (packagePath) -> try - {windowTypes} = Package.loadMetadata(packagePath) ? {} + metadata = Package.loadMetadata(packagePath) ? {} + + if not (metadata.engines?.nylas) and not (/pro/.test(packagePath)) + console.error("INVALID PACKAGE: Your package at #{packagePath} does not have a properly formatted `package.json`. You must include an {'engines': {'nylas': version}} property") + return false + + {windowTypes} = metadata if windowTypes return windowTypes[windowType]? or windowTypes["all"]? else if loadPackagesWhenNoTypesSpecified @@ -417,7 +424,7 @@ class PackageManager @packageDependencies - nasNylasEngine: (packagePath) -> + hasNylasEngine: (packagePath) -> metadata = Package.loadMetadata(packagePath, true) metadata?.engines?.nylas? diff --git a/src/package.coffee b/src/package.coffee index fc94d4f94..a9eba2ecc 100644 --- a/src/package.coffee +++ b/src/package.coffee @@ -42,6 +42,8 @@ class Package metadata = JSON.parse(fs.readFileSync(metadataPath)) catch error throw error unless ignoreErrors + else + return null metadata ?= {} metadata.name = packageName