今年早些时候我试用了 MongoDB Stitch,当时感觉它还不像成品(例如,apps cannot be renamed)。我再试一次,这次我有兴趣了解如何使用 Jest ( this also may not be straightforward) 为我的 Stitch 函数创建自动化测试。
我注意到“功能”部分有一个依赖项测试版 选项卡。在这里,可以将 NPM 模块压缩到压缩包中,它们将在 Stitch JS 环境中可用。我想知道我是否可以使用它来规避我在函数系统中遇到的导入困难 - 相反,我可以从函数对依赖项进行(未经测试的)轻量级调用,然后只测试依赖项。
但是,我希望能够使用控制台命令自动导入我的应用程序,以便在 CI 管道中自动部署。为此,导入/导出也需要包含依赖项,但是 the file-format docs不要提及依赖关系。作为应用程序导入的一部分,是否支持从控制台同步依赖项?
最佳答案
Is there any support for syncing dependencies from the console, as part of an app import?
是的,您可以使用 mongodb-stitch-cli 导入依赖项(v1.10+)。
上传外部依赖:
首先需要一个本地
node_modules
至少包含一个Node.js
的文件夹包裹。如果node_modules
文件夹不存在,npm install <package>
将自动创建它。接下来您需要将它们打包到存档中,以便您可以将它们上传到 Stitch:
tar -czf node_modules.tgz node_modules/
其他支持的格式/扩展名是:
.zip
,.tar
,.gz
,.tgz
接下来您可以将存档放入the functions directory in the application file schema .即
├── functions/ │ └── <function name>/ │ ├── config.json │ └── source.js │ └── node_modules.tgz
使用
--include-dependencies
执行导入命令,即:stitch-cli import --app-id <APP_ID> --path ./your_app --include-dependencies Creating draft for app... Draft created successfully... Importing app... Deploying app... Deploying app... Done. Importing hosting assets... Done.
请注意目前stitch-cli
尚不支持导出依赖项。
另见 Stitch: Upload External Dependencies从用户界面上传。
关于mongodb - MongoDB Stitch 的导入/导出中是否包含依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59229608/