@zuplo/cli 6.60.21 → 6.60.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/engine.test.js.map +1 -1
- package/dist/__tests__/import-openapi-utils.test.js.map +1 -1
- package/dist/__tests__/integration/jest-setup.js.map +1 -1
- package/dist/__tests__/integration/test-utils.d.ts.map +1 -1
- package/dist/__tests__/integration/test-utils.js.map +1 -1
- package/dist/__tests__/outdated.test.js.map +1 -1
- package/dist/__tests__/populate.test.js.map +1 -1
- package/dist/__tests__/tsconfig-upgrader.test.js.map +1 -1
- package/dist/build/handler.d.ts.map +1 -1
- package/dist/build/handler.js.map +1 -1
- package/dist/cli.js.map +1 -1
- package/dist/cmds/source/migrate/runner.d.ts.map +1 -1
- package/dist/cmds/source/migrate/runner.js.map +1 -1
- package/dist/cmds/source/migrate/types.d.ts.map +1 -1
- package/dist/cmds/source/migrate/types.js.map +1 -1
- package/dist/common/alias.d.ts.map +1 -1
- package/dist/common/alias.js.map +1 -1
- package/dist/common/analytics/lib.d.ts.map +1 -1
- package/dist/common/analytics/lib.js.map +1 -1
- package/dist/common/handler.d.ts.map +1 -1
- package/dist/common/handler.js.map +1 -1
- package/dist/common/logger.d.ts.map +1 -1
- package/dist/common/logger.js.map +1 -1
- package/dist/common/machine-id/lib.js.map +1 -1
- package/dist/common/middleware/get-account-param.d.ts.map +1 -1
- package/dist/common/middleware/get-account-param.js.map +1 -1
- package/dist/common/middleware/get-environment-param.js +1 -1
- package/dist/common/middleware/get-environment-param.js.map +1 -1
- package/dist/common/middleware/get-project-param.js.map +1 -1
- package/dist/common/middleware/logging.d.ts.map +1 -1
- package/dist/common/middleware/logging.js.map +1 -1
- package/dist/common/middleware/user-configuration.d.ts.map +1 -1
- package/dist/common/middleware/user-configuration.js.map +1 -1
- package/dist/common/middleware/user-identification.d.ts.map +1 -1
- package/dist/common/middleware/user-identification.js.map +1 -1
- package/dist/common/middleware/validate-fleet.d.ts.map +1 -1
- package/dist/common/middleware/validate-fleet.js.map +1 -1
- package/dist/common/outdated.d.ts.map +1 -1
- package/dist/common/outdated.js.map +1 -1
- package/dist/common/output.d.ts.map +1 -1
- package/dist/common/output.js.map +1 -1
- package/dist/common/settings.d.ts.map +1 -1
- package/dist/common/settings.js +4 -4
- package/dist/common/settings.js.map +1 -1
- package/dist/common/upgraders/vscode-settings-json-upgrader.js.map +1 -1
- package/dist/common/utils/box.js.map +1 -1
- package/dist/common/utils/ports.d.ts.map +1 -1
- package/dist/common/utils/ports.js.map +1 -1
- package/dist/common/validators/file-system-validator.d.ts.map +1 -1
- package/dist/common/validators/file-system-validator.js.map +1 -1
- package/dist/common/validators/lib.d.ts +1 -1
- package/dist/common/validators/lib.d.ts.map +1 -1
- package/dist/common/validators/lib.js.map +1 -1
- package/dist/common/worker-output.d.ts.map +1 -1
- package/dist/common/worker-output.js.map +1 -1
- package/dist/common/xdg/lib.d.ts.map +1 -1
- package/dist/common/xdg/lib.js.map +1 -1
- package/dist/compile/handler.d.ts.map +1 -1
- package/dist/compile/handler.js.map +1 -1
- package/dist/convert/engine.d.ts.map +1 -1
- package/dist/convert/engine.js.map +1 -1
- package/dist/delete/handler.js +1 -1
- package/dist/delete/handler.js.map +1 -1
- package/dist/delete/poll-deployment.d.ts.map +1 -1
- package/dist/delete/poll-deployment.js +0 -1
- package/dist/delete/poll-deployment.js.map +1 -1
- package/dist/deploy/archive.js +1 -1
- package/dist/deploy/archive.js.map +1 -1
- package/dist/deploy/handler.js +3 -3
- package/dist/deploy/handler.js.map +1 -1
- package/dist/deploy/poll-deployment.d.ts.map +1 -1
- package/dist/deploy/poll-deployment.js +8 -14
- package/dist/deploy/poll-deployment.js.map +1 -1
- package/dist/dev/handler.d.ts.map +1 -1
- package/dist/dev/handler.js.map +1 -1
- package/dist/editor/server/cors-plugin.js.map +1 -1
- package/dist/editor/server/server.d.ts.map +1 -1
- package/dist/editor/server/server.js.map +1 -1
- package/dist/editor/server/xfs.js +2 -2
- package/dist/editor/server/xfs.js.map +1 -1
- package/dist/list/handler.d.ts.map +1 -1
- package/dist/list/handler.js.map +1 -1
- package/dist/login/login.d.ts.map +1 -1
- package/dist/login/login.js +1 -1
- package/dist/login/login.js.map +1 -1
- package/dist/login/tokens.d.ts.map +1 -1
- package/dist/login/tokens.js.map +1 -1
- package/dist/project/create/handler.d.ts.map +1 -1
- package/dist/project/create/handler.js.map +1 -1
- package/dist/proxies/create/handler.d.ts.map +1 -1
- package/dist/proxies/create/handler.js.map +1 -1
- package/dist/proxies/delete/handler.d.ts.map +1 -1
- package/dist/proxies/delete/handler.js.map +1 -1
- package/dist/proxies/describe/handler.d.ts.map +1 -1
- package/dist/proxies/describe/handler.js.map +1 -1
- package/dist/proxies/update/handler.d.ts.map +1 -1
- package/dist/proxies/update/handler.js.map +1 -1
- package/dist/source/import-openapi/ajv.d.ts +34 -0
- package/dist/source/import-openapi/ajv.d.ts.map +1 -0
- package/dist/source/import-openapi/ajv.js +2 -0
- package/dist/source/import-openapi/ajv.js.map +1 -0
- package/dist/source/import-openapi/handler.js +2 -2
- package/dist/source/import-openapi/handler.js.map +1 -1
- package/dist/source/import-openapi/interfaces.d.ts +1 -1
- package/dist/source/import-openapi/interfaces.d.ts.map +1 -1
- package/dist/source/import-openapi/interfaces.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/tunnel/create/handler.d.ts.map +1 -1
- package/dist/tunnel/create/handler.js.map +1 -1
- package/dist/tunnel/delete/handler.d.ts.map +1 -1
- package/dist/tunnel/delete/handler.js.map +1 -1
- package/dist/tunnel/delete/poll-teardown-operation.d.ts.map +1 -1
- package/dist/tunnel/delete/poll-teardown-operation.js.map +1 -1
- package/dist/tunnel/describe/handler.d.ts.map +1 -1
- package/dist/tunnel/describe/handler.js.map +1 -1
- package/dist/tunnel/list/handler.d.ts.map +1 -1
- package/dist/tunnel/list/handler.js.map +1 -1
- package/dist/tunnel/models.js.map +1 -1
- package/dist/tunnel/rotate-token/handler.d.ts.map +1 -1
- package/dist/tunnel/rotate-token/handler.js.map +1 -1
- package/dist/tunnel/services/describe/handler.d.ts.map +1 -1
- package/dist/tunnel/services/describe/handler.js.map +1 -1
- package/dist/tunnel/services/update/handler.d.ts.map +1 -1
- package/dist/tunnel/services/update/handler.js.map +1 -1
- package/dist/tunnel/services/update/poll-provisioning-operations.d.ts.map +1 -1
- package/dist/tunnel/services/update/poll-provisioning-operations.js.map +1 -1
- package/dist/variable/create/handler.d.ts.map +1 -1
- package/dist/variable/create/handler.js +1 -1
- package/dist/variable/create/handler.js.map +1 -1
- package/dist/variable/update/handler.d.ts.map +1 -1
- package/dist/variable/update/handler.js +1 -1
- package/dist/variable/update/handler.js.map +1 -1
- package/package.json +4 -4
- package/zup.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-system-validator.js","sourceRoot":"","sources":["../../../src/common/validators/file-system-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAA0B,MAAM,UAAU,CAAC;AAEtE,MAAM,OAAO,mCAAoC,SAAQ,KAAK;IAC5D;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC3E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;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,EAAE;aAC9B,CAAC;QACJ,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,GAAG;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,OAAO,6BAA6B;IAGxC,KAAK,CAAC,QAAQ,CAAC,MAAuB;QACpC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;QACvB,IAAI,CAAC;YACH,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;gBACnC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;YACtB,CAAC;iBAAM,CAAC;gBACN,OAAO;oBACL,EAAE,EAAE,KAAK;oBACT,KAAK,EAAE,IAAI,wBAAwB,EAAE;iBACtC,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,GAAG;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,kBAAkB,CAIhE,IAAI,qBAAqB,EAAE,EAAE,IAAI,+BAA+B,EAAE,CAAC,CAAC;AAEvE,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,kBAAkB,CAE9D,IAAI,qBAAqB,EAAE,EAAE,IAAI,6BAA6B,EAAE,CAAC,CAAC","sourcesContent":["import { existsSync, readdirSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport { findTestFiles } from \"../../test/test-files.js\";\nimport { CompositeValidator, Result, ValidationRule } from \"./lib.js\";\n\nexport class GitBranchOrEnvironmentRequiredError extends Error {\n constructor() {\n super(\n \"Invalid arguments: The project directory is not a Git repository, you must specify the `environment` argument or set `--use-git-branch false` to pick one.\"\n );\n Object.setPrototypeOf(this, NotAGitRepoError.prototype);\n }\n}\n\nexport class NotAGitRepoError extends Error {\n constructor() {\n super(\"Invalid directory: The project directory is not a Git repository.\");\n Object.setPrototypeOf(this, NotAGitRepoError.prototype);\n }\n}\n\nexport class NotAZuploProject extends Error {\n constructor() {\n super(\n \"Invalid directory: The project directory is not the root of a Zuplo project.\"\n );\n Object.setPrototypeOf(this, NotAZuploProject.prototype);\n }\n}\n\nexport class ZuploProjectMissingTests extends Error {\n constructor() {\n super(\n \"Invalid directory: The project directory does not contain any tests (*.test.ts) in the /tests folder. Create a at least one test of the form some-name.test.ts\"\n );\n Object.setPrototypeOf(this, ZuploProjectMissingTests.prototype);\n }\n}\n\nexport class NoGitCommits extends Error {\n constructor() {\n super(\n \"Invalid Git state: The project directory does not contain any commits. Make a commit before deploying.\"\n );\n Object.setPrototypeOf(this, NoGitCommits.prototype);\n }\n}\n\nexport class NotOnAGitBranch extends Error {\n constructor() {\n super(\n \"Invalid Git state: You are not on a branch. Run `git checkout -b <branch-name>` to create a new branch.\"\n );\n Object.setPrototypeOf(this, NotOnAGitBranch.prototype);\n }\n}\n\nexport class GitVersionControlValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n await simpleGit({ baseDir: dir }).status();\n return { ok: true };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_err) {\n return {\n ok: false,\n error: new NotAGitRepoError(),\n };\n }\n }\n}\n\n/**\n * Checks if either the current branch is set as the environment or if\n * the environment is explicitly set\n */\nexport class GitBranchOrEnvironmentValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: {\n dir: string;\n environment: string | undefined;\n }): Promise<Result> {\n const { dir, environment } = option;\n if (typeof environment === \"string\") {\n return {\n ok: true,\n };\n }\n try {\n if (await simpleGit({ baseDir: dir }).checkIsRepo()) {\n await simpleGit({ baseDir: dir }).status();\n const git = simpleGit({ baseDir: dir });\n const branch = await git.branch();\n if (branch.current) {\n return {\n ok: true,\n };\n }\n }\n } catch {\n // Ignore\n }\n return {\n ok: false,\n error: new GitBranchOrEnvironmentRequiredError(),\n };\n }\n}\n\nexport class GitCommitValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n const git = simpleGit({ baseDir: dir });\n const commits = await git.log({ maxCount: 1 });\n if (commits.total === 0) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n return { ok: true };\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n } catch (_err) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n }\n}\n\nexport class GitBranchValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n const git = simpleGit({ baseDir: dir });\n const branch = await git.branch();\n if (!branch.current) {\n return {\n ok: false,\n error: new NotOnAGitBranch(),\n };\n }\n\n return { ok: true };\n }\n}\n\nexport class ZuploProjectValidator implements ValidationRule<{ dir: string }> {\n async validate(options: { dir: string }): Promise<Result> {\n const { dir } = options;\n try {\n const dirPath = path.join(path.normalize(dir), \"config\");\n if (existsSync(dirPath)) {\n const files = readdirSync(dirPath);\n const existingOASFiles =\n files.filter((file) => file.endsWith(\".oas.json\")).length >= 1;\n if (existingOASFiles === true) {\n return { ok: true };\n }\n }\n return {\n ok: false,\n error: new NotAZuploProject(),\n };\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport class ZuploProjectHasTestsValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n if (findTestFiles(dir).length >= 1) {\n return { ok: true };\n } else {\n return {\n ok: false,\n error: new ZuploProjectMissingTests(),\n };\n }\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport const validDeployDirectoryValidator = new CompositeValidator<{\n dir: string;\n project: string | undefined;\n environment: string | undefined;\n}>(new ZuploProjectValidator(), new GitBranchOrEnvironmentValidator());\n\nexport const validTestDirectoryValidator = new CompositeValidator<{\n dir: string;\n}>(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());\n"]}
|
|
1
|
+
{"version":3,"file":"file-system-validator.js","sourceRoot":"","sources":["../../../src/common/validators/file-system-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAA0B,MAAM,UAAU,CAAC;AAEtE,MAAM,OAAO,mCAAoC,SAAQ,KAAK;IAC5D;QACE,KAAK,CACH,4JAA4J,CAC7J,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,mEAAmE,CAAC,CAAC;QAC3E,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CACH,8EAA8E,CAC/E,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACjD;QACE,KAAK,CACH,gKAAgK,CACjK,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,wBAAwB,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC;CACF;AAED,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC;QACE,KAAK,CACH,wGAAwG,CACzG,CAAC;QACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,YAAY,CAAC,SAAS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AAO;oBACL,EAAE,EAAE,KAAK;oBACT,KAAK,EAAE,IAAI,wBAAwB,EAAE;iBACtC,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,KAAK,EAAE,GAAG;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,kBAAkB,CAIhE,IAAI,qBAAqB,EAAE,EAAE,IAAI,+BAA+B,EAAE,CAAC,CAAC;AAEvE,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,kBAAkB,CAE9D,IAAI,qBAAqB,EAAE,EAAE,IAAI,6BAA6B,EAAE,CAAC,CAAC","sourcesContent":["import { existsSync, readdirSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { simpleGit } from \"simple-git\";\nimport { findTestFiles } from \"../../test/test-files.js\";\nimport { CompositeValidator, Result, ValidationRule } from \"./lib.js\";\n\nexport class GitBranchOrEnvironmentRequiredError extends Error {\n constructor() {\n super(\n \"Invalid arguments: The project directory is not a Git repository, you must specify the `environment` argument or set `--use-git-branch false` to pick one.\"\n );\n Object.setPrototypeOf(this, NotAGitRepoError.prototype);\n }\n}\n\nexport class NotAGitRepoError extends Error {\n constructor() {\n super(\"Invalid directory: The project directory is not a Git repository.\");\n Object.setPrototypeOf(this, NotAGitRepoError.prototype);\n }\n}\n\nexport class NotAZuploProject extends Error {\n constructor() {\n super(\n \"Invalid directory: The project directory is not the root of a Zuplo project.\"\n );\n Object.setPrototypeOf(this, NotAZuploProject.prototype);\n }\n}\n\nexport class ZuploProjectMissingTests extends Error {\n constructor() {\n super(\n \"Invalid directory: The project directory does not contain any tests (*.test.ts) in the /tests folder. Create a at least one test of the form some-name.test.ts\"\n );\n Object.setPrototypeOf(this, ZuploProjectMissingTests.prototype);\n }\n}\n\nexport class NoGitCommits extends Error {\n constructor() {\n super(\n \"Invalid Git state: The project directory does not contain any commits. Make a commit before deploying.\"\n );\n Object.setPrototypeOf(this, NoGitCommits.prototype);\n }\n}\n\nexport class NotOnAGitBranch extends Error {\n constructor() {\n super(\n \"Invalid Git state: You are not on a branch. Run `git checkout -b <branch-name>` to create a new branch.\"\n );\n Object.setPrototypeOf(this, NotOnAGitBranch.prototype);\n }\n}\n\nexport class GitVersionControlValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n await simpleGit({ baseDir: dir }).status();\n return { ok: true };\n } catch (_err) {\n return {\n ok: false,\n error: new NotAGitRepoError(),\n };\n }\n }\n}\n\n/**\n * Checks if either the current branch is set as the environment or if\n * the environment is explicitly set\n */\nexport class GitBranchOrEnvironmentValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: {\n dir: string;\n environment: string | undefined;\n }): Promise<Result> {\n const { dir, environment } = option;\n if (typeof environment === \"string\") {\n return {\n ok: true,\n };\n }\n try {\n if (await simpleGit({ baseDir: dir }).checkIsRepo()) {\n await simpleGit({ baseDir: dir }).status();\n const git = simpleGit({ baseDir: dir });\n const branch = await git.branch();\n if (branch.current) {\n return {\n ok: true,\n };\n }\n }\n } catch {\n // Ignore\n }\n return {\n ok: false,\n error: new GitBranchOrEnvironmentRequiredError(),\n };\n }\n}\n\nexport class GitCommitValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n const git = simpleGit({ baseDir: dir });\n const commits = await git.log({ maxCount: 1 });\n if (commits.total === 0) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n return { ok: true };\n } catch (_err) {\n return {\n ok: false,\n error: new NoGitCommits(),\n };\n }\n }\n}\n\nexport class GitBranchValidator implements ValidationRule<{ dir: string }> {\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n const git = simpleGit({ baseDir: dir });\n const branch = await git.branch();\n if (!branch.current) {\n return {\n ok: false,\n error: new NotOnAGitBranch(),\n };\n }\n\n return { ok: true };\n }\n}\n\nexport class ZuploProjectValidator implements ValidationRule<{ dir: string }> {\n async validate(options: { dir: string }): Promise<Result> {\n const { dir } = options;\n try {\n const dirPath = path.join(path.normalize(dir), \"config\");\n if (existsSync(dirPath)) {\n const files = readdirSync(dirPath);\n const existingOASFiles =\n files.filter((file) => file.endsWith(\".oas.json\")).length >= 1;\n if (existingOASFiles === true) {\n return { ok: true };\n }\n }\n return {\n ok: false,\n error: new NotAZuploProject(),\n };\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport class ZuploProjectHasTestsValidator\n implements ValidationRule<{ dir: string }>\n{\n async validate(option: { dir: string }): Promise<Result> {\n const { dir } = option;\n try {\n if (findTestFiles(dir).length >= 1) {\n return { ok: true };\n } else {\n return {\n ok: false,\n error: new ZuploProjectMissingTests(),\n };\n }\n } catch (err) {\n return {\n ok: false,\n error: err,\n };\n }\n }\n}\n\nexport const validDeployDirectoryValidator = new CompositeValidator<{\n dir: string;\n project: string | undefined;\n environment: string | undefined;\n}>(new ZuploProjectValidator(), new GitBranchOrEnvironmentValidator());\n\nexport const validTestDirectoryValidator = new CompositeValidator<{\n dir: string;\n}>(new ZuploProjectValidator(), new ZuploProjectHasTestsValidator());\n"]}
|
|
@@ -12,7 +12,7 @@ export interface ValidationRule<W, V = null, E = Error> {
|
|
|
12
12
|
}
|
|
13
13
|
export declare class CompositeValidator<W> implements ValidationRule<W> {
|
|
14
14
|
private readonly validators;
|
|
15
|
-
constructor(...validators:
|
|
15
|
+
constructor(...validators: ValidationRule<W>[]);
|
|
16
16
|
validate(what: W): Promise<Result>;
|
|
17
17
|
}
|
|
18
18
|
export declare class YargsChecker<W> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../../src/common/validators/lib.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,MAAM,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,KAAK,IACl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,CAAC,CAAC,EAAE;IAIxC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAUzC;AAED,qBAAa,YAAY,CAAC,CAAC;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAoB;gBAElC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;IAIlC,KAAK,CAAC,IAAI,EAAE,CAAC;CAQpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../../src/common/validators/lib.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,kBAAkB;IACZ,UAAU,GAAG,IAAI,KAAK,EAAqB,CAAC;IAE7D,YAAY,GAAG,
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../../src/common/validators/lib.ts"],"names":[],"mappings":"AAQA,MAAM,OAAO,kBAAkB;IACZ,UAAU,GAAG,IAAI,KAAK,EAAqB,CAAC;IAE7D,YAAY,GAAG,UAA+B;QAC5C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,IAAO;QACpB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACnC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;YACzC,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;gBACf,OAAO,MAAM,CAAC;YAChB,CAAC;QACH,CAAC;QAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;IACtB,CAAC;CACF;AAED,MAAM,OAAO,YAAY;IACN,SAAS,CAAoB;IAE9C,YAAY,SAA4B;QACtC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,IAAO;QACjB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF","sourcesContent":["export type Result<V = null, E = Error> =\n | { ok: true; error?: V }\n | { ok: false; error: E };\n\nexport interface ValidationRule<W, V = null, E = Error> {\n validate(what: W): Promise<Result<V, E>> | Result<V, E>;\n}\n\nexport class CompositeValidator<W> implements ValidationRule<W> {\n private readonly validators = new Array<ValidationRule<W>>();\n\n constructor(...validators: ValidationRule<W>[]) {\n this.validators = validators;\n }\n\n async validate(what: W): Promise<Result> {\n for (const rule of this.validators) {\n const result = await rule.validate(what);\n if (!result.ok) {\n return result;\n }\n }\n\n return { ok: true };\n }\n}\n\nexport class YargsChecker<W> {\n private readonly validator: ValidationRule<W>;\n\n constructor(validator: ValidationRule<W>) {\n this.validator = validator;\n }\n\n async check(what: W) {\n const result = await this.validator.validate(what);\n if (!result.ok) {\n return result.error.message;\n } else {\n return true;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-output.d.ts","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-output.d.ts","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAiC,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAO1E,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,QA2JpE;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,SAAI,QAEtE;AAKD,wBAAsB,eAAe,CACnC,KAAK,EAAE,QAAQ,EACf,IAAI,EA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AAK,EAAE,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC,CAChE,CAAC;oBACF,OAAO;gBACT,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;oBACrB,OAAO;gBACT,CAAC;YACH,CAAC;YACD,MAAM,OAAO,CAAC,GAAG,CACf,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;gBAChE,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAEpD,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACrD,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAElD,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["/* eslint-disable no-console */\n\nimport { Readable } from \"node:stream\";\nimport { ConsoleLogEntry, LogFormatter, LogLevel } from \"@zuplo/core/cli\";\nimport { readFile } from \"node:fs/promises\";\n\nconst logFormatter = new LogFormatter(async (path: string) => {\n return readFile(path, { encoding: \"utf8\" });\n});\n\nexport function handleRuntimeStdio(stdout: Readable, stderr: Readable) {\n // ASSUMPTION: each chunk is a whole message from workerd\n // This may not hold across OSes/architectures, but it seems to work on macOS M-line\n // I'm going with this simple approach to avoid complicating this too early\n // We can iterate on this heuristic in the future if it causes issues\n const classifiers = {\n // Is this chunk a big chonky barf from workerd that we want to hijack to cleanup/ignore?\n isBarf(chunk: string) {\n const containsLlvmSymbolizerWarning = chunk.includes(\n \"Not symbolizing stack traces because $LLVM_SYMBOLIZER is not set\"\n );\n const containsRecursiveIsolateLockWarning = chunk.includes(\n \"took recursive isolate lock\"\n );\n // Matches stack traces from workerd\n // - on unix: groups of 9 hex digits separated by spaces\n // - on windows: groups of 12 hex digits, or a single digit 0, separated by spaces\n const containsHexStack = /stack:( (0|[a-f\\d]{4,})){3,}/.test(chunk);\n\n return (\n containsLlvmSymbolizerWarning ||\n containsRecursiveIsolateLockWarning ||\n containsHexStack\n );\n },\n // Is this chunk an Address In Use error?\n isAddressInUse(chunk: string) {\n return chunk.includes(\"Address already in use; toString() = \");\n },\n isWarning(chunk: string) {\n return /\\.c\\+\\+:\\d+: warning:/.test(chunk);\n },\n isCodeMovedWarning(chunk: string) {\n return /CODE_MOVED for unknown code block/.test(chunk);\n },\n isAccessViolation(chunk: string) {\n return chunk.includes(\"access violation;\");\n },\n isZenoLog(chunk: string) {\n return chunk.startsWith(\"[ZENO]:\");\n },\n };\n\n stdout.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // there are no known cases to cleanup yet\n // but, as they are identified, we will do that here\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n logConsole(\"debug\", chunk);\n }\n\n // known case: warnings are not info, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n } else if (classifiers.isZenoLog(chunk)) {\n // Route to the specified logging level\n const levels = [\"debug\", \"info\", \"warn\", \"error\"];\n const level = levels.find((level) =>\n chunk.includes(`[${level.toUpperCase()}]`)\n );\n // Strip the prefixes for zeno and the zeno logging level\n chunk = chunk.substring(\"[ZENO]:\".length);\n chunk = chunk.substring(`[${level?.toUpperCase()}]`.length);\n if (level) {\n logConsole(level as LogLevel, chunk);\n } else {\n logConsole(\"info\", chunk);\n }\n }\n\n // anything not explicitly handled above should be logged as info (via stdout)\n else {\n logConsole(\"error\", chunk);\n }\n });\n\n stderr.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // known case to cleanup: Address in use errors\n if (classifiers.isAddressInUse(chunk)) {\n const address = chunk.match(\n /Address already in use; toString\\(\\) = (.+)\\n/\n )?.[1];\n\n logConsole(\n \"error\",\n `Address already in use (${address}). Please check that you are not already running a server on this address or specify a different port with --port.`\n );\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n // In the past we have seen Access Violation errors on Windows, which may be caused by an outdated\n // version of the Windows OS or the Microsoft Visual C++ Redistributable.\n // See https://github.com/cloudflare/workers-sdk/issues/6170#issuecomment-2245209918\n else if (classifiers.isAccessViolation(chunk)) {\n let error = \"There was an access violation in the runtime.\";\n if (process.platform === \"win32\") {\n error +=\n \"\\nOn Windows, this may be caused by an outdated Microsoft Visual C++ Redistributable library.\\n\" +\n \"Check that you have the latest version installed.\\n\" +\n \"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist.\";\n }\n logConsole(\"error\", error);\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n else {\n logConsole(\"debug\", chunk);\n }\n }\n\n // known case: warnings are not errors, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // known case: \"error: CODE_MOVED for unknown code block?\", warning for workerd devs, not application devs\n else if (classifiers.isCodeMovedWarning(chunk)) {\n // ignore entirely, don't even send it to the debug log file\n }\n\n // Handle Zeno error logs\n else if (classifiers.isZenoLog(chunk)) {\n // Strip the prefixes\n chunk = chunk.substring(\"[ZENO]:\".length);\n chunk = chunk.substring(\"[ERROR]\".length);\n logConsole(\"error\", chunk);\n }\n\n // anything not explicitly handled above should be logged as an error (via stderr)\n else {\n logConsole(\"error\", chunk);\n }\n });\n}\n\nexport function logConsole(level: LogLevel, data: string, callDepth = 0) {\n void logConsoleAsync(level, data, callDepth);\n}\n\n/**\n * This is what is logged when the runtime calls console.log, etc.\n */\nexport async function logConsoleAsync(\n level: LogLevel,\n data: string,\n callDepth = 0\n) {\n try {\n if (!data) {\n return;\n }\n\n // This shouldn't happen, but just in case\n if (typeof data !== \"string\") {\n console[level](data);\n return;\n }\n\n let message = data?.trim();\n if (!message || message?.length === 0) {\n return;\n }\n\n // Probably a JSON object\n if (message.startsWith(`{`) && message.endsWith(`}`)) {\n let logEntry: ConsoleLogEntry;\n try {\n logEntry = JSON.parse(message);\n } catch {\n // If we are at a depth of 1 it means we are trying to handle the case\n // where a chunk might be multiple JSON entries.\n if (callDepth === 1) {\n // We might have multiple log entries in a single chunk\n // so split them and log each one\n const lines = message.split(\"\\n\");\n await Promise.all(\n lines.map(async (line) => logConsole(level, line, callDepth++))\n );\n return;\n } else {\n console[level](data);\n return;\n }\n }\n await Promise.all(\n logEntry.messages.map(async (msg) => {\n const line = await logFormatter.formatStructured(logEntry, msg);\n console[level](line);\n })\n );\n } else {\n message = await logFormatter.formatMessage(message);\n\n const line = logFormatter.formatLine(level, message);\n console[level](line);\n }\n } catch {\n const line = logFormatter.formatLine(level, data);\n\n console[level](line);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"worker-output.js","sourceRoot":"","sources":["../../src/common/worker-output.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmB,YAAY,EAAY,MAAM,iBAAiB,CAAC;AAC1E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB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D,MAAM,OAAO,CAAC,GAAG,CACf,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBAClC,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,gBAAgB,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;gBAChE,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;YACvB,CAAC,CAAC,CACH,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,OAAO,GAAG,MAAM,YAAY,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;YAEpD,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACrD,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAElD,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC;IACvB,CAAC;AACH,CAAC","sourcesContent":["/** biome-ignore-all lint/suspicious/noConsole: Output */\nimport { Readable } from \"node:stream\";\nimport { ConsoleLogEntry, LogFormatter, LogLevel } from \"@zuplo/core/cli\";\nimport { readFile } from \"node:fs/promises\";\n\nconst logFormatter = new LogFormatter(async (path: string) => {\n return readFile(path, { encoding: \"utf8\" });\n});\n\nexport function handleRuntimeStdio(stdout: Readable, stderr: Readable) {\n // ASSUMPTION: each chunk is a whole message from workerd\n // This may not hold across OSes/architectures, but it seems to work on macOS M-line\n // I'm going with this simple approach to avoid complicating this too early\n // We can iterate on this heuristic in the future if it causes issues\n const classifiers = {\n // Is this chunk a big chonky barf from workerd that we want to hijack to cleanup/ignore?\n isBarf(chunk: string) {\n const containsLlvmSymbolizerWarning = chunk.includes(\n \"Not symbolizing stack traces because $LLVM_SYMBOLIZER is not set\"\n );\n const containsRecursiveIsolateLockWarning = chunk.includes(\n \"took recursive isolate lock\"\n );\n // Matches stack traces from workerd\n // - on unix: groups of 9 hex digits separated by spaces\n // - on windows: groups of 12 hex digits, or a single digit 0, separated by spaces\n const containsHexStack = /stack:( (0|[a-f\\d]{4,})){3,}/.test(chunk);\n\n return (\n containsLlvmSymbolizerWarning ||\n containsRecursiveIsolateLockWarning ||\n containsHexStack\n );\n },\n // Is this chunk an Address In Use error?\n isAddressInUse(chunk: string) {\n return chunk.includes(\"Address already in use; toString() = \");\n },\n isWarning(chunk: string) {\n return /\\.c\\+\\+:\\d+: warning:/.test(chunk);\n },\n isCodeMovedWarning(chunk: string) {\n return /CODE_MOVED for unknown code block/.test(chunk);\n },\n isAccessViolation(chunk: string) {\n return chunk.includes(\"access violation;\");\n },\n isZenoLog(chunk: string) {\n return chunk.startsWith(\"[ZENO]:\");\n },\n };\n\n stdout.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // there are no known cases to cleanup yet\n // but, as they are identified, we will do that here\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n logConsole(\"debug\", chunk);\n }\n\n // known case: warnings are not info, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n } else if (classifiers.isZenoLog(chunk)) {\n // Route to the specified logging level\n const levels = [\"debug\", \"info\", \"warn\", \"error\"];\n const level = levels.find((level) =>\n chunk.includes(`[${level.toUpperCase()}]`)\n );\n // Strip the prefixes for zeno and the zeno logging level\n chunk = chunk.substring(\"[ZENO]:\".length);\n chunk = chunk.substring(`[${level?.toUpperCase()}]`.length);\n if (level) {\n logConsole(level as LogLevel, chunk);\n } else {\n logConsole(\"info\", chunk);\n }\n }\n\n // anything not explicitly handled above should be logged as info (via stdout)\n else {\n logConsole(\"error\", chunk);\n }\n });\n\n stderr.on(\"data\", (chunk: Buffer | string) => {\n chunk = chunk.toString().trim();\n\n if (classifiers.isBarf(chunk)) {\n // this is a big chonky barf from workerd that we want to hijack to cleanup/ignore\n\n // CLEANABLE:\n // known case to cleanup: Address in use errors\n if (classifiers.isAddressInUse(chunk)) {\n const address = chunk.match(\n /Address already in use; toString\\(\\) = (.+)\\n/\n )?.[1];\n\n logConsole(\n \"error\",\n `Address already in use (${address}). Please check that you are not already running a server on this address or specify a different port with --port.`\n );\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n // In the past we have seen Access Violation errors on Windows, which may be caused by an outdated\n // version of the Windows OS or the Microsoft Visual C++ Redistributable.\n // See https://github.com/cloudflare/workers-sdk/issues/6170#issuecomment-2245209918\n else if (classifiers.isAccessViolation(chunk)) {\n let error = \"There was an access violation in the runtime.\";\n if (process.platform === \"win32\") {\n error +=\n \"\\nOn Windows, this may be caused by an outdated Microsoft Visual C++ Redistributable library.\\n\" +\n \"Check that you have the latest version installed.\\n\" +\n \"See https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist.\";\n }\n logConsole(\"error\", error);\n\n // Log the original error to the debug logs.\n logConsole(\"debug\", chunk);\n }\n\n // IGNORABLE:\n // anything else not handled above is considered ignorable\n // so send it to the debug logs which are discarded unless\n // the user explicitly sets a logLevel indicating they care\n else {\n logConsole(\"debug\", chunk);\n }\n }\n\n // known case: warnings are not errors, log them as such\n else if (classifiers.isWarning(chunk)) {\n logConsole(\"warn\", chunk);\n }\n\n // known case: \"error: CODE_MOVED for unknown code block?\", warning for workerd devs, not application devs\n else if (classifiers.isCodeMovedWarning(chunk)) {\n // ignore entirely, don't even send it to the debug log file\n }\n\n // Handle Zeno error logs\n else if (classifiers.isZenoLog(chunk)) {\n // Strip the prefixes\n chunk = chunk.substring(\"[ZENO]:\".length);\n chunk = chunk.substring(\"[ERROR]\".length);\n logConsole(\"error\", chunk);\n }\n\n // anything not explicitly handled above should be logged as an error (via stderr)\n else {\n logConsole(\"error\", chunk);\n }\n });\n}\n\nexport function logConsole(level: LogLevel, data: string, callDepth = 0) {\n void logConsoleAsync(level, data, callDepth);\n}\n\n/**\n * This is what is logged when the runtime calls console.log, etc.\n */\nexport async function logConsoleAsync(\n level: LogLevel,\n data: string,\n callDepth = 0\n) {\n try {\n if (!data) {\n return;\n }\n\n // This shouldn't happen, but just in case\n if (typeof data !== \"string\") {\n console[level](data);\n return;\n }\n\n let message = data?.trim();\n if (!message || message?.length === 0) {\n return;\n }\n\n // Probably a JSON object\n if (message.startsWith(`{`) && message.endsWith(`}`)) {\n let logEntry: ConsoleLogEntry;\n try {\n logEntry = JSON.parse(message);\n } catch {\n // If we are at a depth of 1 it means we are trying to handle the case\n // where a chunk might be multiple JSON entries.\n if (callDepth === 1) {\n // We might have multiple log entries in a single chunk\n // so split them and log each one\n const lines = message.split(\"\\n\");\n await Promise.all(\n lines.map(async (line) => logConsole(level, line, callDepth++))\n );\n return;\n } else {\n console[level](data);\n return;\n }\n }\n await Promise.all(\n logEntry.messages.map(async (msg) => {\n const line = await logFormatter.formatStructured(logEntry, msg);\n console[level](line);\n })\n );\n } else {\n message = await logFormatter.formatMessage(message);\n\n const line = logFormatter.formatLine(level, message);\n console[level](line);\n }\n } catch {\n const line = logFormatter.formatLine(level, data);\n\n console[level](line);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../../src/common/xdg/lib.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../../../src/common/xdg/lib.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,eAAe,QAG3B,CAAC;AACF,eAAO,MAAM,aAAa,QAGzB,CAAC;AACF,eAAO,MAAM,cAAc,QAG1B,CAAC;AACF,eAAO,MAAM,qBAAqB,QAGjC,CAAC;AACF,eAAO,MAAM,mBAAmB,QAG/B,CAAC;AACF,eAAO,MAAM,oBAAoB,QAGhC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../../src/common/xdg/lib.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../../src/common/xdg/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,SAAS,2BAA2B,CAAC,OAAe,EAAE,QAAgB;IAEpE,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;QAEzB,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAW,CAAC;IACxC,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC;AACH,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,2BAA2B,CACxD,iBAAiB,EACjB,SAAS,CACV,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG,2BAA2B,CACtD,eAAe,EACf,cAAc,CACf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG,2BAA2B,CACvD,eAAe,EACf,cAAc,CACf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAC5C,eAAe,EACf,yBAAyB,CAC1B,CAAC;AACF,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,IAAI,CAC1C,aAAa,EACb,yBAAyB,CAC1B,CAAC;AACF,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAC3C,cAAc,EACd,yBAAyB,CAC1B,CAAC","sourcesContent":["import { homedir } from \"node:os\";\nimport path from \"node:path\";\nimport { ZUPLO_CLI_XDG_FOLDER_NAME } from \"../constants.js\";\n\nfunction defineDirectoryWithFallback(xdgName: string, fallback: string) {\n // biome-ignore lint/style/noProcessEnv: Migrated from ESLint\n if (process.env[xdgName]) {\n // biome-ignore lint/style/noProcessEnv: Migrated from ESLint\n return process.env[xdgName] as string;\n } else {\n return path.join(homedir(), fallback);\n }\n}\n\nexport const XDG_CONFIG_HOME = defineDirectoryWithFallback(\n \"XDG_CONFIG_HOME\",\n \".config\"\n);\nexport const XDG_DATA_HOME = defineDirectoryWithFallback(\n \"XDG_DATA_HOME\",\n \".local/share\"\n);\nexport const XDG_STATE_HOME = defineDirectoryWithFallback(\n \"XDG_DATA_HOME\",\n \".local/state\"\n);\nexport const ZUPLO_XDG_CONFIG_HOME = path.join(\n XDG_CONFIG_HOME,\n ZUPLO_CLI_XDG_FOLDER_NAME\n);\nexport const ZUPLO_XDG_DATA_HOME = path.join(\n XDG_DATA_HOME,\n ZUPLO_CLI_XDG_FOLDER_NAME\n);\nexport const ZUPLO_XDG_STATE_HOME = path.join(\n XDG_STATE_HOME,\n ZUPLO_CLI_XDG_FOLDER_NAME\n);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/compile/handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../src/compile/handler.ts"],"names":[],"mappings":"AAcA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAsB,OAAO,CAAC,IAAI,EAAE,SAAS,iBA+E5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/compile/handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":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AC,CAAC;IACzD,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;QAC5C,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;IAMD,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAC;IAE7C,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC;IAE1B,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,UAAU,EAAE,CAAC;IAEjD,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,oBAAoB,CAAC;YAC9B,OAAO;YACP,MAAM,EAAE,IAAI,aAAa,EAAE;YAC3B,eAAe;YACf,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;YAC/B,IAAI,EAAE,OAAO;YACb,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;YAC/B,+BAA+B,EAAE,QAAQ;gBACvC,CAAC,CAAC;oBAEE,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB;oBAE/C,kBAAkB,EAAE,QAAQ,CAAC,kBAAkB;oBAE/C,sBAAsB,EAAE,QAAQ,CAAC,sBAAsB;iBACxD;gBACH,CAAC;oBACC,SAAS;YACb,MAAM;YACN,kBAAkB;SACnB,CAAC,CAAC;QAEH,yBAAyB,CAAC,yCAAyC,CAAC,CAAC;QACrE,MAAM,qCAAqC,CACzC,8BAA8B,eAAe,SAAS,IAAI,CAAC,aAAa,CAAC,EAAE,CAC5E,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,yBAAyB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,oCAAoC,CACxC,kCAAkC,CACnC,CAAC;IACJ,CAAC;AACH,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport { cpSync, existsSync, readFileSync } from \"node:fs\";\nimport { join, relative, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport dotenv from \"dotenv\";\nimport { logger } from \"../common/logger.js\";\nimport {\n ConsoleOutput,\n printCriticalFailureToConsoleAndExit,\n printDiagnosticsToConsole,\n printResultToConsoleAndExitGracefully,\n} from \"../common/output.js\";\nimport { handleRuntimeStdio } from \"../common/worker-output.js\";\n\nexport interface Arguments {\n dir: string;\n \"bundled-dir\": string;\n port: number;\n \"binary-name\": string;\n \"build-id\": string;\n}\n\nexport async function compile(argv: Arguments) {\n const sourceDirectory = resolve(join(relative(process.cwd(), argv.dir)));\n\n // When we build, we MIGHT need to use the @zuplo/runtime from the node_modules if the user\n // has installed our packages using https://www.npmjs.com/package/zuplo in a global directory\n\n // Try to copy the @zuplo/runtime locally\n const zuploRuntimePath = new URL(\n \"../../node_modules/@zuplo/runtime\",\n import.meta.url\n );\n if (existsSync(zuploRuntimePath)) {\n cpSync(\n zuploRuntimePath,\n join(sourceDirectory, \"node_modules/@zuplo/runtime\"),\n {\n recursive: true,\n dereference: true,\n }\n );\n }\n\n // Set GLOBAL_MODULE_LOCATION to the location of the CLIs node_modules\n // biome-ignore lint/style/noProcessEnv: Migrated from ESLint\n process.env.GLOBAL_MODULE_LOCATION = fileURLToPath(\n new URL(\"../../node_modules\", import.meta.url)\n );\n\n // Check if the user has a .env.zuplo file\n let envZuplo: dotenv.DotenvParseOutput = {};\n const envZuploFile = join(sourceDirectory, \".env.zuplo\");\n if (existsSync(envZuploFile)) {\n const contents = readFileSync(envZuploFile);\n envZuplo = dotenv.parse(contents);\n }\n // Set other variables using __ZUPLO_CONFIG as necessary\n // const config = {\n // };\n // process.env.__ZUPLO_CONFIG = btoa(JSON.stringify(config));\n // Use a dynamic import so that setting process.env has effect\n const core = await import(\"@zuplo/core/cli\");\n\n const zupPort = argv.port;\n\n const buildId = argv[\"build-id\"] || randomUUID();\n\n try {\n await core.compileWorkerdServer({\n buildId,\n output: new ConsoleOutput(),\n sourceDirectory,\n bundledDir: argv[\"bundled-dir\"],\n port: zupPort,\n binaryName: argv[\"binary-name\"],\n publicZuploEnvironmentVariables: envZuplo\n ? {\n // biome-ignore lint/style/useNamingConvention: External API property\n ZUPLO_ACCOUNT_NAME: envZuplo.ZUPLO_ACCOUNT_NAME,\n // biome-ignore lint/style/useNamingConvention: External API property\n ZUPLO_PROJECT_NAME: envZuplo.ZUPLO_PROJECT_NAME,\n // biome-ignore lint/style/useNamingConvention: External API property\n ZUPLO_ENVIRONMENT_TYPE: envZuplo.ZUPLO_ENVIRONMENT_TYPE,\n }\n : // Leave this as undefined to simulate the old behavior\n undefined,\n logger,\n handleRuntimeStdio,\n });\n\n printDiagnosticsToConsole(\"📦 Compiled a self-contained zup binary\");\n await printResultToConsoleAndExitGracefully(\n `The binary is available at ${sourceDirectory}/dist/${argv[\"binary-name\"]}`\n );\n } catch (err) {\n printDiagnosticsToConsole(err.message);\n await printCriticalFailureToConsoleAndExit(\n \"Failed to compile the zup binary\"\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/convert/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/convert/engine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,wBAAgB,aAAa,CAAC,YAAY,EAAE,eAAe;;;;;;;EAsE1D;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,eAAe;;;EAQtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/convert/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/convert/engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,MAAM,UAAU,aAAa,CAAC,YAA6B;IACzD,MAAM,IA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AS,yBAAyB;IAChC,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE;YACJ,KAAK,EAAE,mCAAmC;YAC1C,OAAO,EAAE,OAAO;SACjB;QACD,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CACf,IAAuC,EACvC,OAAwB;IAExB,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAC3C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,CAC/B,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC;IAChB,OAAO,IAAI,CAAC,aAAa,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AACxC,CAAC","sourcesContent":["import { join } from \"node:path\";\nimport { RouteConfigFile } from \"./routes.legacy.js\";\n\nexport function convertRoutes(routesConfig: RouteConfigFile) {\n const base = generateBaseOpenAPIConfig();\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n const paths = base.paths as any;\n\n routesConfig.routes.forEach((route) => {\n const pathObjectKey = fullPath(route, routesConfig);\n\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n let pathObject: any;\n if (!paths[pathObjectKey]) {\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n pathObject = {} as any;\n // Default the path to url-pattern\n pathObject[\"x-zuplo-path\"] = {\n pathMode: \"url-pattern\",\n };\n paths[pathObjectKey] = pathObject;\n }\n\n pathObject = paths[pathObjectKey];\n\n const operationKey = route.methods.map((m) => m.toLowerCase()).join(\",\");\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n const operation = {} as any;\n\n if (route.excludeFromOpenApi) {\n operation[\"x-internal\"] = true;\n }\n\n operation[\"summary\"] = route.summary;\n operation[\"description\"] = route.description;\n operation[\"operationId\"] = route.operationId;\n\n // Support for openapi types we supported for a short time\n // for a while that some customers are actually using\n const routeWithOpenApi = route as {\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n responses?: any;\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n parameters?: any;\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n tags?: any;\n };\n if (routeWithOpenApi.parameters) {\n operation[\"parameters\"] = routeWithOpenApi.parameters;\n }\n if (routeWithOpenApi.responses) {\n operation[\"responses\"] = routeWithOpenApi.responses;\n }\n if (routeWithOpenApi.tags) {\n operation[\"tags\"] = routeWithOpenApi.tags;\n }\n\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n const xZuploRoute = {} as any;\n if (route.corsPolicy) xZuploRoute[\"corsPolicy\"] = route.corsPolicy;\n if (route.custom) xZuploRoute[\"custom\"] = route.custom;\n if (route.policies) xZuploRoute[\"policies\"] = route.policies;\n if (route.key) xZuploRoute[\"key\"] = route.key;\n if (route.label) xZuploRoute[\"label\"] = route.label;\n\n xZuploRoute[\"handler\"] = route.handler;\n\n operation[\"x-zuplo-route\"] = xZuploRoute;\n\n pathObject[operationKey] = operation;\n });\n\n return base;\n}\n\nexport function convertPolicies(routes: RouteConfigFile) {\n const policies = routes.policies;\n const corsPolicies = routes.corsPolicies;\n\n return {\n policies: policies ? [...policies] : [],\n corsPolicies: corsPolicies ? [...corsPolicies] : [],\n };\n}\n\n// Utilities\n////////////\n\nfunction generateBaseOpenAPIConfig() {\n return {\n openapi: \"3.1.0\",\n info: {\n title: \"Converted from config/routes.json\",\n version: \"1.0.0\",\n },\n paths: {},\n };\n}\n\nfunction fullPath(\n path: { path: string; version: string },\n context: RouteConfigFile\n) {\n const versionPrefix = context.versions.filter(\n (v) => v.name === path.version\n )[0].pathPrefix;\n return join(versionPrefix, path.path);\n}\n"]}
|
package/dist/delete/handler.js
CHANGED
|
@@ -78,7 +78,7 @@ async function deleteFromSelfHosted(argv) {
|
|
|
78
78
|
async function checkUrl(argv, deploymentName) {
|
|
79
79
|
let url = argv.url;
|
|
80
80
|
if (!/^(http:\/\/|https:\/\/)/i.test(argv.url)) {
|
|
81
|
-
url =
|
|
81
|
+
url = `https://${url}`;
|
|
82
82
|
}
|
|
83
83
|
const parsedUrl = new URL(url);
|
|
84
84
|
if (parsedUrl.username || parsedUrl.password) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/delete/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,oCAAoC,EACpC,qCAAqC,GACtC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AActD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAe;IAC7C,IAAI,IAAI,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,IAAsB,CAAC;QACpC,MAAM,oBAAoB,CAAC,IAAI,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,IAAe;IAE3C,IAAI,cAAc,CAAC;IACnB,IAAI,CAAC;QACH,cAAc,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;QAC7C,MAAM,oCAAoC,CACxC,mCAAmC,IAAI,CAAC,GAAG,wCAAwC,CACpF,CAAC;IACJ,CAAC;IAGD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAClC,MAAM,cAAc,GAAG,MAAM,KAAK,CAChC,GAAG,QAAQ,CAAC,4BAA4B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C,CACxC,sCAAsC,SAAS,CAAC,QAAQ,8BAA8B,CACvF,CAAC;IACJ,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC5B,MAAM,CAAC,KAAK,CACV,iDAAiD,SAAS,CAAC,MAAM,EAAE,CACpE,CAAC;QACF,MAAM,oCAAoC,CACxC,2CAA2C,SAAS,CAAC,MAAM,8BAA8B,CAC1F,CAAC;IACJ,CAAC;IAED,cAAc,GAAG,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import { normalize } from \"node:path\";\nimport { logger } from \"../common/logger.js\";\nimport {\n printCriticalFailureToConsoleAndExit,\n printResultToConsoleAndExitGracefully,\n} from \"../common/output.js\";\nimport settings from \"../common/settings.js\";\nimport { RequiredProperties } from \"../common/utils/types.js\";\nimport { pingDeployment } from \"./poll-deployment.js\";\n\nexport interface Arguments {\n account: string;\n project: string;\n url: string;\n authToken: string;\n wait: boolean;\n \"self-hosted-endpoint\"?: string;\n}\n\ntype SelfHostedArgs = RequiredProperties<Arguments, \"self-hosted-endpoint\">;\n\n// delete is a reserved keyword in JavaScript, so we call this function deleteZup\nexport async function deleteZup(argv: Arguments) {\n if (argv[\"self-hosted-endpoint\"]) {\n const args = argv as SelfHostedArgs;\n await deleteFromSelfHosted(args);\n } else {\n await deleteFromSaas(argv);\n }\n}\n\nasync function deleteFromSaas(argv: Arguments) {\n // 1. Extract the URL and normalize\n let deploymentName;\n try {\n deploymentName = await checkUrl(argv, deploymentName);\n } catch (err) {\n logger.error(err, \"Failed to parse the URL\");\n await printCriticalFailureToConsoleAndExit(\n `Error: Failed to parse the URL: ${argv.url}. Ensure you have entered a valid URL.`\n );\n }\n\n // 2. Build delete request\n const { account, project } = argv;\n const deleteResponse = await fetch(\n `${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/deployments/${deploymentName}`,\n {\n method: \"DELETE\",\n headers: {\n // biome-ignore lint/style/useNamingConvention: External API property\n Authorization: `Bearer ${argv.authToken}`,\n },\n }\n );\n\n if (deleteResponse.ok) {\n if (argv.wait) {\n // 3. Poll until the deployment is no longer available\n const deleted = await pingDeployment(argv);\n if (!deleted) {\n logger.error(\n `Failed to confirm deletion of zup within alloted time frame.`\n );\n await printCriticalFailureToConsoleAndExit(\n `Error: Failed to confirm deletion of zup within alloted time frame of ${\n settings.MAX_POLL_RETRIES * settings.POLL_INTERVAL\n } ms. Your zup is still be available at ${argv.url}.`\n );\n } else {\n await printResultToConsoleAndExitGracefully(`Deleted ${argv.url}`);\n }\n } else {\n await printResultToConsoleAndExitGracefully(\n `Enqueued deletion of ${argv.url}`\n );\n }\n } else {\n logger.error(\n {\n status: deleteResponse.status,\n statusText: deleteResponse.statusText,\n },\n \"Failed to enqueue the deletion request\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to enqueue the deletion request. Try again later.\"\n );\n }\n}\n\nasync function deleteFromSelfHosted(argv: SelfHostedArgs) {\n // 1. Extract the URL and normalize\n let deploymentName;\n try {\n deploymentName = await checkUrl(argv, deploymentName);\n } catch (err) {\n logger.error(err, \"Failed to parse the URL\");\n await printCriticalFailureToConsoleAndExit(\n `Error: Failed to parse the URL: ${argv.url}. Ensure you have entered a valid URL.`\n );\n }\n\n // 2. Build delete request\n const endpoint = normalize(argv[\"self-hosted-endpoint\"]);\n const deleteResponse = await fetch(\n `${endpoint}/v1/deployments/${deploymentName}`,\n {\n method: \"DELETE\",\n headers: {\n // biome-ignore lint/style/useNamingConvention: External API property\n Authorization: `Bearer ${argv.authToken}`,\n },\n }\n );\n\n if (deleteResponse.ok) {\n await printResultToConsoleAndExitGracefully(\n `Enqueued deletion of ${argv.url}`\n );\n } else {\n logger.error(\n JSON.stringify(await deleteResponse.json(), null, 2),\n \"Failed to upload to self-hosted build endpoint\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to enqueue the deletion request. Try again later.\"\n );\n }\n}\n\nasync function checkUrl(argv: Arguments, deploymentName: unknown) {\n let url = argv.url;\n if (!/^(http:\\/\\/|https:\\/\\/)/i.test(argv.url)) {\n url = `https://${url}`;\n }\n const parsedUrl = new URL(url);\n\n if (parsedUrl.username || parsedUrl.password) {\n logger.error(`Extra username and/or password was included in the URL.`);\n await printCriticalFailureToConsoleAndExit(\n `Error: Extraneous username and/or password in the URL. Only include the hostname.`\n );\n }\n\n if (parsedUrl.pathname !== \"/\") {\n logger.error(\n `Extra pathname was included in the URL: ${parsedUrl.pathname}`\n );\n await printCriticalFailureToConsoleAndExit(\n `Error: Extraneous pathname in URL: ${parsedUrl.pathname}. Only include the hostname.`\n );\n }\n\n if (parsedUrl.search !== \"\") {\n logger.error(\n `Extra search params were included in the URL: ${parsedUrl.search}`\n );\n await printCriticalFailureToConsoleAndExit(\n `Error: Extraneous search params in URL: ${parsedUrl.search}. Only include the hostname.`\n );\n }\n\n deploymentName = parsedUrl.hostname.split(\".\")[0];\n return deploymentName;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll-deployment.d.ts","sourceRoot":"","sources":["../../src/delete/poll-deployment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMzC,wBAAsB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"poll-deployment.d.ts","sourceRoot":"","sources":["../../src/delete/poll-deployment.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMzC,wBAAsB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAetE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll-deployment.js","sourceRoot":"","sources":["../../src/delete/poll-deployment.ts"],"names":[],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3E,yBAAyB,CACvB,kDAAkD,SAAS,IAAI,QAAQ,CAAC,gBAAgB,GAAG,CAC5F,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC;QAC1D,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YAEjB,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,EAAE,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { printDiagnosticsToConsole } from \"../common/output.js\";\nimport settings from \"../common/settings.js\";\nimport { Arguments } from \"./handler.js\";\n\nfunction wait(duration: number = settings.POLL_INTERVAL): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, duration));\n}\n\nexport async function pingDeployment(argv: Arguments): Promise<boolean> {\n for (let pollRetry = 0; pollRetry < settings.MAX_POLL_RETRIES; pollRetry++) {\n printDiagnosticsToConsole(\n `Waiting for Zuplo deployment to be deleted... (${pollRetry}/${settings.MAX_POLL_RETRIES})`\n );\n const response = await fetch(`${argv.url}/__zuplo/build`);\n if (!response.ok) {\n // That means that we no longer have a 2xx response from the zup\n return true;\n } else {\n await wait();\n }\n }\n\n return false;\n}\n"]}
|
package/dist/deploy/archive.js
CHANGED
|
@@ -102,7 +102,7 @@ export async function generateMetadata(argv) {
|
|
|
102
102
|
"--contains",
|
|
103
103
|
branchCommit.current,
|
|
104
104
|
]);
|
|
105
|
-
if (brancheRef
|
|
105
|
+
if (brancheRef?.all?.[0]) {
|
|
106
106
|
const originBranch = brancheRef.all[0];
|
|
107
107
|
const cleanOriginBranch = originBranch.replace(/^origin\//, "");
|
|
108
108
|
if (!cleanOriginBranch) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"archive.js","sourceRoot":"","sources":["../../src/deploy/archive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,a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AAE,IAAI,EAAE,CAAC,CAAC,EACjC;QACE,IAAI,EAAE,GAAG;KACV,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport {\n Stats,\n existsSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join, relative, sep } from \"node:path\";\nimport ignore from \"ignore\";\nimport { minimatch } from \"minimatch\";\nimport { simpleGit } from \"simple-git\";\nimport * as tar from \"tar\";\nimport { DEPLOYER_METADATA_FILE } from \"../common/constants.js\";\nimport { logger } from \"../common/logger.js\";\nimport { Arguments } from \"./handler.js\";\n\nexport const ARCHIVE_EXTENSION = \".tar.gz\";\n\nfunction createTempFileWithSuffix(suffix = ARCHIVE_EXTENSION) {\n const tempDir = tmpdir();\n const randomName = randomBytes(16).toString(\"hex\");\n const tempFilePath = join(tempDir, `${randomName}${suffix}`);\n return tempFilePath;\n}\n\nexport async function archive(argv: Arguments) {\n const tarball = createTempFileWithSuffix();\n const dir = argv.dir;\n const ignoreFn = createIgnoreFunction(dir);\n const normalizedDir = join(relative(process.cwd(), dir));\n\n const metadata = await prepareDeployerMetadata(argv);\n\n await tar.create(\n {\n gzip: true,\n file: tarball,\n filter: (path, stat) => {\n const stats = stat as unknown as Stats;\n const normalizedPath = stats.isDirectory()\n ? join(relative(process.cwd(), path), sep) // add / to help the ignore module determine that this is a folder\n : join(relative(process.cwd(), path));\n\n // special case to allow for processing of the root by tar (./)\n if (minimatch(normalizedPath, \"/\", { windowsPathsNoEscape: true })) {\n return true;\n }\n\n if (\n minimatch(normalizedPath, \".zuplo/\", { windowsPathsNoEscape: true })\n ) {\n // Need to return true to allow this to process the entries of the directory\n return true;\n }\n\n if (\n minimatch(normalizedPath, `.zuplo/${DEPLOYER_METADATA_FILE}`, {\n windowsPathsNoEscape: true,\n })\n ) {\n // Now on the second round when it enters the .zuplo folder, we specifically look for this file\n return true;\n }\n\n // We special case the .env files to allow for the self-hosted endpoint to be passed in\n if (normalizedPath === \".env\" || normalizedPath === \".env.zuplo\") {\n if (argv[\"self-hosted-endpoint\"]) {\n return true;\n }\n }\n\n const result = ignoreFn.ignores(normalizedPath);\n logger.trace(`${normalizedPath} ignored: ${result}`);\n\n // The way `tar` interprets true|false is \"opposite\" from ignore\n // When ignore returns true, it means that the .ignore file doesn't want it.\n // When tar return true, it means that we want it.\n return !result;\n },\n },\n [normalizedDir]\n );\n return {\n tarball,\n metadata,\n };\n}\n\n// Note that we do not recursively create an ignore function for each dir\n// We only create one for the top-level of the directory\nexport function createIgnoreFunction(normalizedDir: string) {\n // Most ignore files forget to ignore the .git directory\n\n // Need to do this conversion because of some weird confusion with the d.ts for ignore package in esm\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const baseIgnore = (ignore as any)().add(\".git/\");\n\n if (existsSync(`${normalizedDir}/.zupignore`)) {\n const zupignorePath = `${normalizedDir}/.zupignore`;\n logger.debug(`Using ${zupignorePath} to filter out files`);\n return baseIgnore.add(readFileSync(zupignorePath).toString());\n } else if (existsSync(`${normalizedDir}/.gitignore`)) {\n const gitignorePath = `${normalizedDir}/.gitignore`;\n logger.debug(`Using ${gitignorePath} to filter out files`);\n const gitIgnoreContent = readFileSync(gitignorePath).toString();\n // @NOTE - we should always include the .zuplo folder\n const gitIgnoreContentDotZuploRemoved = gitIgnoreContent.replace(\n /\\.zuplo[/]/,\n \"\"\n );\n return baseIgnore.add(gitIgnoreContentDotZuploRemoved);\n } else {\n logger.debug(\n \"Didn't find a .gitignore or .zupignore file. Defaulting to ignoring .git and node_modules.\"\n );\n return baseIgnore.add(\"node_modules/\");\n }\n}\n\ninterface DeployerMetadata {\n branch: string;\n repoUrl: string | undefined;\n sha: string | undefined;\n}\n\nasync function prepareDeployerMetadata(argv: Arguments) {\n const dir = argv.dir;\n const metadata = await generateMetadata(argv);\n await writeGeneratedMetadata(dir, metadata);\n return metadata;\n}\n\nexport async function generateMetadata(argv: Arguments) {\n const dir = argv.dir;\n const git = simpleGit({ baseDir: dir });\n\n const isRepo = await git.checkIsRepo();\n let branch: string;\n if (argv.environment) {\n branch = argv.environment;\n } else if (isRepo) {\n // Get the current branch from Git\n const status = await git.status();\n if (!status.current) {\n throw new Error(\"Invalid state: Directory is in detached head state.\");\n }\n branch = status.current.trim();\n\n // @NOTE - gitlab returns HEAD as the current branch when running git.status()\n // https://forum.gitlab.com/t/why-i-cant-get-the-branch-name/72462/6\n if (branch === \"HEAD\") {\n // Fetch remote branches to ensure the latest information\n await git.fetch([\"--all\"]);\n\n const branchCommit = await git.branch([\"-a\"]);\n const brancheRef = await git.branch([\n \"-r\",\n \"--contains\",\n branchCommit.current,\n ]);\n if (brancheRef && brancheRef.all && brancheRef.all[0]) {\n const originBranch = brancheRef.all[0];\n const cleanOriginBranch = originBranch.replace(/^origin\\//, \"\");\n if (!cleanOriginBranch) {\n throw new Error(\n \"Invalid state: Directory is in detached head state.\"\n );\n }\n branch = cleanOriginBranch.trim();\n }\n }\n } else {\n throw new Error(\n \"The argument `environment` is required when not in a git repository.\"\n );\n }\n\n // Get the current sha\n let sha: string | undefined;\n let repoUrl: string | undefined;\n if (argv[\"override-repo-url\"]) {\n repoUrl = argv[\"override-repo-url\"];\n } else if (isRepo) {\n sha = (await git.revparse([\"HEAD\"])).trim();\n try {\n repoUrl = (await git.listRemote([\"--get-url\"])).trim();\n } catch {\n logger.debug(\n \"Failed to get the remote URL from the git repository. This can happen if there is no remote configured.\"\n );\n repoUrl = undefined;\n }\n }\n\n return {\n branch,\n repoUrl,\n sha,\n };\n}\n\nasync function writeGeneratedMetadata(dir: string, metadata: DeployerMetadata) {\n try {\n mkdirSync(join(dir, \".zuplo\"));\n } catch (err) {\n if (err.code === \"EEXIST\") {\n // this is fine, which means that we don't create it and move on\n } else {\n throw err;\n }\n }\n writeFileSync(\n join(dir, \".zuplo\", DEPLOYER_METADATA_FILE),\n JSON.stringify(metadata, null, 2),\n {\n flag: \"w\",\n }\n );\n}\n"]}
|
|
1
|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G,EAAE,QAAQ,EAAE,sBAAsB,CAAC,EAC3C,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,EACjC;QACE,IAAI,EAAE,GAAG;KACV,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport {\n Stats,\n existsSync,\n mkdirSync,\n readFileSync,\n writeFileSync,\n} from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join, relative, sep } from \"node:path\";\nimport ignore from \"ignore\";\nimport { minimatch } from \"minimatch\";\nimport { simpleGit } from \"simple-git\";\nimport * as tar from \"tar\";\nimport { DEPLOYER_METADATA_FILE } from \"../common/constants.js\";\nimport { logger } from \"../common/logger.js\";\nimport { Arguments } from \"./handler.js\";\n\nexport const ARCHIVE_EXTENSION = \".tar.gz\";\n\nfunction createTempFileWithSuffix(suffix = ARCHIVE_EXTENSION) {\n const tempDir = tmpdir();\n const randomName = randomBytes(16).toString(\"hex\");\n const tempFilePath = join(tempDir, `${randomName}${suffix}`);\n return tempFilePath;\n}\n\nexport async function archive(argv: Arguments) {\n const tarball = createTempFileWithSuffix();\n const dir = argv.dir;\n const ignoreFn = createIgnoreFunction(dir);\n const normalizedDir = join(relative(process.cwd(), dir));\n\n const metadata = await prepareDeployerMetadata(argv);\n\n await tar.create(\n {\n gzip: true,\n file: tarball,\n filter: (path, stat) => {\n const stats = stat as unknown as Stats;\n const normalizedPath = stats.isDirectory()\n ? join(relative(process.cwd(), path), sep) // add / to help the ignore module determine that this is a folder\n : join(relative(process.cwd(), path));\n\n // special case to allow for processing of the root by tar (./)\n if (minimatch(normalizedPath, \"/\", { windowsPathsNoEscape: true })) {\n return true;\n }\n\n if (\n minimatch(normalizedPath, \".zuplo/\", { windowsPathsNoEscape: true })\n ) {\n // Need to return true to allow this to process the entries of the directory\n return true;\n }\n\n if (\n minimatch(normalizedPath, `.zuplo/${DEPLOYER_METADATA_FILE}`, {\n windowsPathsNoEscape: true,\n })\n ) {\n // Now on the second round when it enters the .zuplo folder, we specifically look for this file\n return true;\n }\n\n // We special case the .env files to allow for the self-hosted endpoint to be passed in\n if (normalizedPath === \".env\" || normalizedPath === \".env.zuplo\") {\n if (argv[\"self-hosted-endpoint\"]) {\n return true;\n }\n }\n\n const result = ignoreFn.ignores(normalizedPath);\n logger.trace(`${normalizedPath} ignored: ${result}`);\n\n // The way `tar` interprets true|false is \"opposite\" from ignore\n // When ignore returns true, it means that the .ignore file doesn't want it.\n // When tar return true, it means that we want it.\n return !result;\n },\n },\n [normalizedDir]\n );\n return {\n tarball,\n metadata,\n };\n}\n\n// Note that we do not recursively create an ignore function for each dir\n// We only create one for the top-level of the directory\nexport function createIgnoreFunction(normalizedDir: string) {\n // Most ignore files forget to ignore the .git directory\n\n // Need to do this conversion because of some weird confusion with the d.ts for ignore package in esm\n // biome-ignore lint/suspicious/noExplicitAny: Migrated from ESLint\n const baseIgnore = (ignore as any)().add(\".git/\");\n\n if (existsSync(`${normalizedDir}/.zupignore`)) {\n const zupignorePath = `${normalizedDir}/.zupignore`;\n logger.debug(`Using ${zupignorePath} to filter out files`);\n return baseIgnore.add(readFileSync(zupignorePath).toString());\n } else if (existsSync(`${normalizedDir}/.gitignore`)) {\n const gitignorePath = `${normalizedDir}/.gitignore`;\n logger.debug(`Using ${gitignorePath} to filter out files`);\n const gitIgnoreContent = readFileSync(gitignorePath).toString();\n // @NOTE - we should always include the .zuplo folder\n const gitIgnoreContentDotZuploRemoved = gitIgnoreContent.replace(\n /\\.zuplo[/]/,\n \"\"\n );\n return baseIgnore.add(gitIgnoreContentDotZuploRemoved);\n } else {\n logger.debug(\n \"Didn't find a .gitignore or .zupignore file. Defaulting to ignoring .git and node_modules.\"\n );\n return baseIgnore.add(\"node_modules/\");\n }\n}\n\ninterface DeployerMetadata {\n branch: string;\n repoUrl: string | undefined;\n sha: string | undefined;\n}\n\nasync function prepareDeployerMetadata(argv: Arguments) {\n const dir = argv.dir;\n const metadata = await generateMetadata(argv);\n await writeGeneratedMetadata(dir, metadata);\n return metadata;\n}\n\nexport async function generateMetadata(argv: Arguments) {\n const dir = argv.dir;\n const git = simpleGit({ baseDir: dir });\n\n const isRepo = await git.checkIsRepo();\n let branch: string;\n if (argv.environment) {\n branch = argv.environment;\n } else if (isRepo) {\n // Get the current branch from Git\n const status = await git.status();\n if (!status.current) {\n throw new Error(\"Invalid state: Directory is in detached head state.\");\n }\n branch = status.current.trim();\n\n // @NOTE - gitlab returns HEAD as the current branch when running git.status()\n // https://forum.gitlab.com/t/why-i-cant-get-the-branch-name/72462/6\n if (branch === \"HEAD\") {\n // Fetch remote branches to ensure the latest information\n await git.fetch([\"--all\"]);\n\n const branchCommit = await git.branch([\"-a\"]);\n const brancheRef = await git.branch([\n \"-r\",\n \"--contains\",\n branchCommit.current,\n ]);\n if (brancheRef?.all?.[0]) {\n const originBranch = brancheRef.all[0];\n const cleanOriginBranch = originBranch.replace(/^origin\\//, \"\");\n if (!cleanOriginBranch) {\n throw new Error(\n \"Invalid state: Directory is in detached head state.\"\n );\n }\n branch = cleanOriginBranch.trim();\n }\n }\n } else {\n throw new Error(\n \"The argument `environment` is required when not in a git repository.\"\n );\n }\n\n // Get the current sha\n let sha: string | undefined;\n let repoUrl: string | undefined;\n if (argv[\"override-repo-url\"]) {\n repoUrl = argv[\"override-repo-url\"];\n } else if (isRepo) {\n sha = (await git.revparse([\"HEAD\"])).trim();\n try {\n repoUrl = (await git.listRemote([\"--get-url\"])).trim();\n } catch {\n logger.debug(\n \"Failed to get the remote URL from the git repository. This can happen if there is no remote configured.\"\n );\n repoUrl = undefined;\n }\n }\n\n return {\n branch,\n repoUrl,\n sha,\n };\n}\n\nasync function writeGeneratedMetadata(dir: string, metadata: DeployerMetadata) {\n try {\n mkdirSync(join(dir, \".zuplo\"));\n } catch (err) {\n if (err.code === \"EEXIST\") {\n // this is fine, which means that we don't create it and move on\n } else {\n throw err;\n }\n }\n writeFileSync(\n join(dir, \".zuplo\", DEPLOYER_METADATA_FILE),\n JSON.stringify(metadata, null, 2),\n {\n flag: \"w\",\n }\n );\n}\n"]}
|
package/dist/deploy/handler.js
CHANGED
|
@@ -179,14 +179,14 @@ function restoreExistingZuploEnvAsNecessary(argv, originalValue) {
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
const getPrettyBranch = (branch) => {
|
|
182
|
-
return
|
|
182
|
+
return branch
|
|
183
183
|
.normalize("NFD")
|
|
184
184
|
.replace(/[\u0300-\u036f]/g, "")
|
|
185
185
|
.replace(/([^\w]+|\s+)/g, "-")
|
|
186
|
-
.replace(
|
|
186
|
+
.replace(/--+/g, "-")
|
|
187
187
|
.replace(/(^-+|-+$)/, "")
|
|
188
188
|
.replaceAll("_", "-")
|
|
189
189
|
.toLowerCase()
|
|
190
|
-
.substring(0, MAX_PRETTY_BRANCH_LENGTH)
|
|
190
|
+
.substring(0, MAX_PRETTY_BRANCH_LENGTH);
|
|
191
191
|
};
|
|
192
192
|
//# sourceMappingURL=handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/deploy/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,sBAAsB,IAAI,wBAAwB,EAClD,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,oCAAoC,EACpC,yBAAyB,EACzB,qCAAqC,EACrC,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,C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G,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;IACzD,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;IAC9D,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5B,MAAM,cAAc,GAAG,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC1D,OAAO,cAAc,CAAC;IACxB,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,kCAAkC,CACzC,IAAoB,EACpB,aAAiC;IAEjC,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACrB,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;QACzD,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;QAC9D,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE;IAEjD,OAAO,CACL,MAAM;SACH,SAAS,CAAC,KAAK,CAAC;SAChB,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;SAC/B,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC;SAE7B,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;SACtB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;SACpB,WAAW,EAAE;SACb,SAAS,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAC1C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport {\n MAX_PRETTY_BRANCH_NAME as MAX_PRETTY_BRANCH_LENGTH,\n ZUPLO_SYSTEM_ENV_VAR,\n} from \"../common/constants.js\";\nimport { logger } from \"../common/logger.js\";\nimport {\n printCriticalFailureToConsoleAndExit,\n printDiagnosticsToConsole,\n printResultToConsoleAndExitGracefully,\n printSpinnerToConsole,\n printWarningToConsole,\n} from \"../common/output.js\";\nimport settings from \"../common/settings.js\";\nimport { RequiredProperties } from \"../common/utils/types.js\";\nimport { normalizeUrl } from \"../common/utils/urls.js\";\nimport { pullSystemConfig } from \"../common/populate.js\";\nimport { archive, generateMetadata } from \"./archive.js\";\nimport {\n UnableToAutoLinkToExistingProject,\n retrieveOrCreateEnvironment,\n} from \"./environments.js\";\nimport { upload } from \"./file-upload.js\";\nimport { pollBuild, pollDeployment } from \"./poll-deployment.js\";\n\nexport interface Arguments {\n account: string;\n project: string;\n dir: string;\n environment?: string;\n authToken: string;\n \"verify-remote\"?: boolean;\n \"self-hosted-endpoint\"?: string;\n \"override-repo-url\"?: string;\n}\n\nexport type SelfHostedArgs = RequiredProperties<\n Arguments,\n \"self-hosted-endpoint\"\n>;\n\nexport async function deploy(argv: Arguments) {\n if (argv[\"self-hosted-endpoint\"]) {\n const args = argv as SelfHostedArgs;\n await deployToSelfHosted(args);\n } else {\n await deployToSaas(argv);\n }\n}\n\nasync function deployToSaas(argv: Arguments) {\n // 1. Create the tarball locally\n const archiveMetadata = await archive(argv);\n logger.debug(`Tarball created locally at ${archiveMetadata.tarball}`);\n\n // 2. Build uploadUrl request\n const { account, project } = argv;\n\n const payload = {\n accountName: account,\n projectName: project,\n environment: archiveMetadata.metadata.branch,\n repositoryUrl: archiveMetadata.metadata.repoUrl,\n sha: archiveMetadata.metadata.sha,\n };\n\n const uploadUrlResponse = await fetch(\n `${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/deployments/source-url`,\n {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${argv.authToken}`,\n },\n body: JSON.stringify(payload),\n }\n );\n\n logger.debug(`Upload URL response: ${uploadUrlResponse.status}`);\n\n if (uploadUrlResponse.ok) {\n // 3. Upload to request URL\n const { uploadUrl, deploymentId } = await uploadUrlResponse.json();\n\n const uploadResponse = await upload({\n tarballPath: archiveMetadata.tarball,\n uploadUrl,\n deploymentId,\n ...payload,\n });\n\n logger.debug(`Upload response: ${uploadResponse.status}`);\n\n if (uploadResponse.ok) {\n const spinner = printSpinnerToConsole(\n `Deploying the '${payload.environment}' environment to '${project}' on account '${account}'...`\n );\n\n const { url, logUrl } = await pollDeployment(\n argv,\n deploymentId,\n account,\n project,\n spinner\n );\n if (url) {\n await printResultToConsoleAndExitGracefully(\n `Deployed to ${url}`,\n spinner\n );\n } else {\n await printCriticalFailureToConsoleAndExit(\n `Failed to deploy the environment ${\n archiveMetadata.metadata.branch\n } to project ${project} on account ${account}.\\nDeployment ID: ${deploymentId}\\nFor more information, check the deployment logs in the Zuplo dashboard.\\n\n ${logUrl}`,\n spinner\n );\n }\n } else {\n logger.error(\n {\n status: uploadResponse.status,\n statusText: uploadResponse.statusText,\n },\n \"Failed to upload source to cloud storage\"\n );\n printDiagnosticsToConsole(\n \"Error: Failed to upload deployment source. Please try again.\"\n );\n }\n } else {\n logger.error(\n {\n status: uploadUrlResponse.status,\n statusText: uploadUrlResponse.statusText,\n },\n \"Failed to retrieve uploadUrl\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to upload deployment source. Please try again.\"\n );\n }\n}\n\nasync function deployToSelfHosted(argv: SelfHostedArgs) {\n const { account, project } = argv;\n\n let existingZuploEnv: string | undefined;\n\n try {\n // 0. Finagle the URL first\n const endpoint = normalizeUrl(argv[\"self-hosted-endpoint\"]);\n\n // 1. Perform the link on-behalf-of-the-user\n // Store the current .env.zuplo if there is one and restore it later\n existingZuploEnv = retrieveExistingZuploEnv(argv);\n const branch = (await generateMetadata(argv)).branch;\n try {\n const environmentToAutoLink = await retrieveOrCreateEnvironment(\n branch,\n argv\n );\n await pullSystemConfig({\n dir: argv.dir,\n environment: environmentToAutoLink.name,\n authToken: argv.authToken,\n });\n } catch (error) {\n if (\n error instanceof UnableToAutoLinkToExistingProject &&\n // eslint-disable-next-line node/no-process-env\n process.env.ZUPLO_ALLOW_DEPLOY_WITH_EMPTY_VARS\n ) {\n printWarningToConsole(\n `We are unable to fetch the environment variables from Zuplo for this project. \nDeployment will proceed because ZUPLO_ALLOW_DEPLOY_WITH_EMPTY_VARS is set. \nHowever, the environment variables will not be available. \nTo fix this, check that the project, ${argv.project} exists and this api-key has access to it.`\n );\n } else if (error instanceof UnableToAutoLinkToExistingProject) {\n await printCriticalFailureToConsoleAndExit(\n `We are unable to fetch the environment variables from Zuplo for this project. \nTo fix this, check that the project, ${argv.project} exists and this api-key has access to it.\nIf you want to force deployment without the environment variables, set ZUPLO_ALLOW_DEPLOY_WITH_EMPTY_VARS to true.`\n );\n } else {\n logger.error(error, \"Failed to fetch environment variables\");\n await printCriticalFailureToConsoleAndExit(\n `We are unable to fetch the environment variables from Zuplo for this project. \nTo fix this, check that the project, ${argv.project} exists and this api-key has access to it.`\n );\n }\n }\n\n // 2. Create the tarball locally\n const archiveMetadata = await archive(argv);\n logger.debug(`Tarball created locally at ${archiveMetadata.tarball}`);\n\n // 3. Build uploadUrl request\n const form = new FormData();\n const deploymentName = `${project}-${getPrettyBranch(\n archiveMetadata.metadata.branch\n )}`;\n form.set(\n \"file\",\n new Blob([readFileSync(archiveMetadata.tarball)], {\n type: \"application/gzip\",\n })\n );\n form.set(\"projectName\", project);\n form.set(\"deploymentName\", deploymentName);\n\n const uploadUrlResponse = await fetch(`${endpoint}/v1/deployments/build`, {\n method: \"POST\",\n headers: {\n Authorization: `Bearer ${argv.authToken}`,\n },\n body: form,\n });\n\n logger.debug(`Upload URL response: ${uploadUrlResponse.status}`);\n\n if (uploadUrlResponse.ok) {\n const spinner = printSpinnerToConsole(\n `Deploying the current branch ${archiveMetadata.metadata.branch} to project ${project} on account ${account}...`\n );\n\n // 4. Poll for build\n const { buildName } = await uploadUrlResponse.json();\n\n logger.debug(`Deployment started for ${buildName}`);\n\n const buildResult = await pollBuild(argv, endpoint, buildName, spinner);\n\n if (buildResult.conditionType === \"Complete\") {\n // Retrieve the deployment\n const deploymentResponse = await fetch(\n `${endpoint}/v1/deployments/${deploymentName}`,\n {\n method: \"GET\",\n headers: {\n Authorization: `Bearer ${argv.authToken}`,\n },\n }\n );\n const deploymentJSON: { deploymentUrl: string } =\n await deploymentResponse.json();\n restoreExistingZuploEnvAsNecessary(argv, existingZuploEnv);\n\n await printResultToConsoleAndExitGracefully(\n `Deployed to ${deploymentJSON.deploymentUrl}`,\n spinner\n );\n } else {\n restoreExistingZuploEnvAsNecessary(argv, existingZuploEnv);\n await printCriticalFailureToConsoleAndExit(\n `Failed to deploy the current environment. Here's the diagnostics: ${JSON.stringify(\n buildResult\n )}`,\n spinner\n );\n }\n } else {\n logger.error(\n await uploadUrlResponse.text(),\n \"Failed to upload to self-hosted build endpoint\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to upload to self-hosted build endpoint\"\n );\n }\n } catch (error) {\n logger.error(error);\n } finally {\n restoreExistingZuploEnvAsNecessary(argv, existingZuploEnv);\n }\n}\n\nfunction retrieveExistingZuploEnv(argv: SelfHostedArgs): string | undefined {\n const dir = argv.dir;\n const normalizedDir = join(relative(process.cwd(), dir));\n const envFilePath = join(normalizedDir, ZUPLO_SYSTEM_ENV_VAR);\n if (existsSync(envFilePath)) {\n const envFileContent = readFileSync(envFilePath, \"utf-8\");\n return envFileContent;\n } else {\n return undefined;\n }\n}\n\nfunction restoreExistingZuploEnvAsNecessary(\n argv: SelfHostedArgs,\n originalValue: string | undefined\n) {\n if (originalValue) {\n const dir = argv.dir;\n const normalizedDir = join(relative(process.cwd(), dir));\n const envFilePath = join(normalizedDir, ZUPLO_SYSTEM_ENV_VAR);\n writeFileSync(envFilePath, originalValue);\n }\n}\n\nconst getPrettyBranch = (branch: string): string => {\n // https://ricardometring.com/javascript-replace-special-characters\n return (\n branch\n .normalize(\"NFD\")\n .replace(/[\\u0300-\\u036f]/g, \"\") // Remove accents\n .replace(/([^\\w]+|\\s+)/g, \"-\") // Replace space and other characters by hyphen\n // eslint-disable-next-line no-useless-escape\n .replace(/\\-\\-+/g, \"-\") // Replaces multiple hyphens by one hyphen\n .replace(/(^-+|-+$)/, \"\") // Remove extra hyphens from beginning or end of the string\n .replaceAll(\"_\", \"-\") // Replace underscores by hyphens (Url hosts cannot have underscores)\n .toLowerCase()\n .substring(0, MAX_PRETTY_BRANCH_LENGTH)\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/deploy/handler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EACL,sBAAsB,IAAI,wBAAwB,EAClD,oBAAoB,GACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EACL,oCAAoC,EACpC,yBAAyB,EACzB,qCAAqC,EACrC,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,EACL,iCAAiC,EACjC,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAkBjE,MAAM,CAAC,KAAK,UAAU,M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cAAc,CAAC;IACxB,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,SAAS,kCAAkC,CACzC,IAAoB,EACpB,aAAiC;IAEjC,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACrB,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC;QACzD,MAAM,WAAW,GAAG,IAAI,CAAC,aAAa,EAAE,oBAAoB,CAAC,CAAC;QAC9D,aAAa,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IAC5C,CAAC;AACH,CAAC;AAED,MAAM,eAAe,GAAG,CAAC,MAAc,EAAU,EAAE;IAEjD,OAAO,MAAM;SACV,SAAS,CAAC,KAAK,CAAC;SAChB,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC;SAC/B,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC;SAC7B,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;SACpB,WAAW,EAAE;SACb,SAAS,CAAC,CAAC,EAAE,wBAAwB,CAAC,CAAC;AAC5C,CAAC,CAAC","sourcesContent":["import { existsSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join, relative } from \"node:path\";\nimport {\n MAX_PRETTY_BRANCH_NAME as MAX_PRETTY_BRANCH_LENGTH,\n ZUPLO_SYSTEM_ENV_VAR,\n} from \"../common/constants.js\";\nimport { logger } from \"../common/logger.js\";\nimport {\n printCriticalFailureToConsoleAndExit,\n printDiagnosticsToConsole,\n printResultToConsoleAndExitGracefully,\n printSpinnerToConsole,\n printWarningToConsole,\n} from \"../common/output.js\";\nimport settings from \"../common/settings.js\";\nimport { RequiredProperties } from \"../common/utils/types.js\";\nimport { normalizeUrl } from \"../common/utils/urls.js\";\nimport { pullSystemConfig } from \"../common/populate.js\";\nimport { archive, generateMetadata } from \"./archive.js\";\nimport {\n UnableToAutoLinkToExistingProject,\n retrieveOrCreateEnvironment,\n} from \"./environments.js\";\nimport { upload } from \"./file-upload.js\";\nimport { pollBuild, pollDeployment } from \"./poll-deployment.js\";\n\nexport interface Arguments {\n account: string;\n project: string;\n dir: string;\n environment?: string;\n authToken: string;\n \"verify-remote\"?: boolean;\n \"self-hosted-endpoint\"?: string;\n \"override-repo-url\"?: string;\n}\n\nexport type SelfHostedArgs = RequiredProperties<\n Arguments,\n \"self-hosted-endpoint\"\n>;\n\nexport async function deploy(argv: Arguments) {\n if (argv[\"self-hosted-endpoint\"]) {\n const args = argv as SelfHostedArgs;\n await deployToSelfHosted(args);\n } else {\n await deployToSaas(argv);\n }\n}\n\nasync function deployToSaas(argv: Arguments) {\n // 1. Create the tarball locally\n const archiveMetadata = await archive(argv);\n logger.debug(`Tarball created locally at ${archiveMetadata.tarball}`);\n\n // 2. Build uploadUrl request\n const { account, project } = argv;\n\n const payload = {\n accountName: account,\n projectName: project,\n environment: archiveMetadata.metadata.branch,\n repositoryUrl: archiveMetadata.metadata.repoUrl,\n sha: archiveMetadata.metadata.sha,\n };\n\n const uploadUrlResponse = await fetch(\n `${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/deployments/source-url`,\n {\n method: \"POST\",\n headers: {\n // biome-ignore lint/style/useNamingConvention: External API property\n Authorization: `Bearer ${argv.authToken}`,\n },\n body: JSON.stringify(payload),\n }\n );\n\n logger.debug(`Upload URL response: ${uploadUrlResponse.status}`);\n\n if (uploadUrlResponse.ok) {\n // 3. Upload to request URL\n const { uploadUrl, deploymentId } = await uploadUrlResponse.json();\n\n const uploadResponse = await upload({\n tarballPath: archiveMetadata.tarball,\n uploadUrl,\n deploymentId,\n ...payload,\n });\n\n logger.debug(`Upload response: ${uploadResponse.status}`);\n\n if (uploadResponse.ok) {\n const spinner = printSpinnerToConsole(\n `Deploying the '${payload.environment}' environment to '${project}' on account '${account}'...`\n );\n\n const { url, logUrl } = await pollDeployment(\n argv,\n deploymentId,\n account,\n project,\n spinner\n );\n if (url) {\n await printResultToConsoleAndExitGracefully(\n `Deployed to ${url}`,\n spinner\n );\n } else {\n await printCriticalFailureToConsoleAndExit(\n `Failed to deploy the environment ${\n archiveMetadata.metadata.branch\n } to project ${project} on account ${account}.\\nDeployment ID: ${deploymentId}\\nFor more information, check the deployment logs in the Zuplo dashboard.\\n\n ${logUrl}`,\n spinner\n );\n }\n } else {\n logger.error(\n {\n status: uploadResponse.status,\n statusText: uploadResponse.statusText,\n },\n \"Failed to upload source to cloud storage\"\n );\n printDiagnosticsToConsole(\n \"Error: Failed to upload deployment source. Please try again.\"\n );\n }\n } else {\n logger.error(\n {\n status: uploadUrlResponse.status,\n statusText: uploadUrlResponse.statusText,\n },\n \"Failed to retrieve uploadUrl\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to upload deployment source. Please try again.\"\n );\n }\n}\n\nasync function deployToSelfHosted(argv: SelfHostedArgs) {\n const { account, project } = argv;\n\n let existingZuploEnv: string | undefined;\n\n try {\n // 0. Finagle the URL first\n const endpoint = normalizeUrl(argv[\"self-hosted-endpoint\"]);\n\n // 1. Perform the link on-behalf-of-the-user\n // Store the current .env.zuplo if there is one and restore it later\n existingZuploEnv = retrieveExistingZuploEnv(argv);\n const branch = (await generateMetadata(argv)).branch;\n try {\n const environmentToAutoLink = await retrieveOrCreateEnvironment(\n branch,\n argv\n );\n await pullSystemConfig({\n dir: argv.dir,\n environment: environmentToAutoLink.name,\n authToken: argv.authToken,\n });\n } catch (error) {\n if (\n error instanceof UnableToAutoLinkToExistingProject &&\n // biome-ignore lint/style/noProcessEnv: Migrated from ESLint\n process.env.ZUPLO_ALLOW_DEPLOY_WITH_EMPTY_VARS\n ) {\n printWarningToConsole(\n `We are unable to fetch the environment variables from Zuplo for this project. \nDeployment will proceed because ZUPLO_ALLOW_DEPLOY_WITH_EMPTY_VARS is set. \nHowever, the environment variables will not be available. \nTo fix this, check that the project, ${argv.project} exists and this api-key has access to it.`\n );\n } else if (error instanceof UnableToAutoLinkToExistingProject) {\n await printCriticalFailureToConsoleAndExit(\n `We are unable to fetch the environment variables from Zuplo for this project. \nTo fix this, check that the project, ${argv.project} exists and this api-key has access to it.\nIf you want to force deployment without the environment variables, set ZUPLO_ALLOW_DEPLOY_WITH_EMPTY_VARS to true.`\n );\n } else {\n logger.error(error, \"Failed to fetch environment variables\");\n await printCriticalFailureToConsoleAndExit(\n `We are unable to fetch the environment variables from Zuplo for this project. \nTo fix this, check that the project, ${argv.project} exists and this api-key has access to it.`\n );\n }\n }\n\n // 2. Create the tarball locally\n const archiveMetadata = await archive(argv);\n logger.debug(`Tarball created locally at ${archiveMetadata.tarball}`);\n\n // 3. Build uploadUrl request\n const form = new FormData();\n const deploymentName = `${project}-${getPrettyBranch(\n archiveMetadata.metadata.branch\n )}`;\n form.set(\n \"file\",\n new Blob([readFileSync(archiveMetadata.tarball)], {\n type: \"application/gzip\",\n })\n );\n form.set(\"projectName\", project);\n form.set(\"deploymentName\", deploymentName);\n\n const uploadUrlResponse = await fetch(`${endpoint}/v1/deployments/build`, {\n method: \"POST\",\n headers: {\n // biome-ignore lint/style/useNamingConvention: External API property\n Authorization: `Bearer ${argv.authToken}`,\n },\n body: form,\n });\n\n logger.debug(`Upload URL response: ${uploadUrlResponse.status}`);\n\n if (uploadUrlResponse.ok) {\n const spinner = printSpinnerToConsole(\n `Deploying the current branch ${archiveMetadata.metadata.branch} to project ${project} on account ${account}...`\n );\n\n // 4. Poll for build\n const { buildName } = await uploadUrlResponse.json();\n\n logger.debug(`Deployment started for ${buildName}`);\n\n const buildResult = await pollBuild(argv, endpoint, buildName, spinner);\n\n if (buildResult.conditionType === \"Complete\") {\n // Retrieve the deployment\n const deploymentResponse = await fetch(\n `${endpoint}/v1/deployments/${deploymentName}`,\n {\n method: \"GET\",\n headers: {\n // biome-ignore lint/style/useNamingConvention: External API property\n Authorization: `Bearer ${argv.authToken}`,\n },\n }\n );\n const deploymentJSON: { deploymentUrl: string } =\n await deploymentResponse.json();\n restoreExistingZuploEnvAsNecessary(argv, existingZuploEnv);\n\n await printResultToConsoleAndExitGracefully(\n `Deployed to ${deploymentJSON.deploymentUrl}`,\n spinner\n );\n } else {\n restoreExistingZuploEnvAsNecessary(argv, existingZuploEnv);\n await printCriticalFailureToConsoleAndExit(\n `Failed to deploy the current environment. Here's the diagnostics: ${JSON.stringify(\n buildResult\n )}`,\n spinner\n );\n }\n } else {\n logger.error(\n await uploadUrlResponse.text(),\n \"Failed to upload to self-hosted build endpoint\"\n );\n await printCriticalFailureToConsoleAndExit(\n \"Error: Failed to upload to self-hosted build endpoint\"\n );\n }\n } catch (error) {\n logger.error(error);\n } finally {\n restoreExistingZuploEnvAsNecessary(argv, existingZuploEnv);\n }\n}\n\nfunction retrieveExistingZuploEnv(argv: SelfHostedArgs): string | undefined {\n const dir = argv.dir;\n const normalizedDir = join(relative(process.cwd(), dir));\n const envFilePath = join(normalizedDir, ZUPLO_SYSTEM_ENV_VAR);\n if (existsSync(envFilePath)) {\n const envFileContent = readFileSync(envFilePath, \"utf-8\");\n return envFileContent;\n } else {\n return undefined;\n }\n}\n\nfunction restoreExistingZuploEnvAsNecessary(\n argv: SelfHostedArgs,\n originalValue: string | undefined\n) {\n if (originalValue) {\n const dir = argv.dir;\n const normalizedDir = join(relative(process.cwd(), dir));\n const envFilePath = join(normalizedDir, ZUPLO_SYSTEM_ENV_VAR);\n writeFileSync(envFilePath, originalValue);\n }\n}\n\nconst getPrettyBranch = (branch: string): string => {\n // https://ricardometring.com/javascript-replace-special-characters\n return branch\n .normalize(\"NFD\")\n .replace(/[\\u0300-\\u036f]/g, \"\") // Remove accents\n .replace(/([^\\w]+|\\s+)/g, \"-\") // Replace space and other characters by hyphen\n .replace(/--+/g, \"-\") // Replaces multiple hyphens by one hyphen\n .replace(/(^-+|-+$)/, \"\") // Remove extra hyphens from beginning or end of the string\n .replaceAll(\"_\", \"-\") // Replace underscores by hyphens (Url hosts cannot have underscores)\n .toLowerCase()\n .substring(0, MAX_PRETTY_BRANCH_LENGTH);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll-deployment.d.ts","sourceRoot":"","sources":["../../src/deploy/poll-deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAO1B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMzC,wBAAsB,cAAc,CAClC,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,GAAG,GACX,OAAO,CAAC;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"poll-deployment.d.ts","sourceRoot":"","sources":["../../src/deploy/poll-deployment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAO1B,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMzC,wBAAsB,cAAc,CAClC,IAAI,EAAE,SAAS,EACf,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,GAAG,GACX,OAAO,CAAC;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC,CAoG3C;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,GAAG,GACX,OAAO,CAAC;IACT,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC,CAsDD"}
|
|
@@ -5,8 +5,8 @@ function wait(duration = settings.POLL_INTERVAL) {
|
|
|
5
5
|
return new Promise((resolve) => setTimeout(resolve, duration));
|
|
6
6
|
}
|
|
7
7
|
export async function pollDeployment(argv, fileId, account, project, spinner) {
|
|
8
|
-
const
|
|
9
|
-
let
|
|
8
|
+
const maxRetryAttemptsForServerUpdates = 5;
|
|
9
|
+
let currentRetryAttemptsForServerUpdates = 0;
|
|
10
10
|
for (let pollRetry = 0; pollRetry < settings.MAX_POLL_RETRIES; pollRetry++) {
|
|
11
11
|
spinner.suffixText = `(${pollRetry}/${settings.MAX_POLL_RETRIES})`;
|
|
12
12
|
const response = await fetch(`${settings.ZUPLO_DEVELOPER_API_ENDPOINT}/v1/accounts/${account}/projects/${project}/deployment-status/${fileId}`, {
|
|
@@ -67,14 +67,11 @@ export async function pollDeployment(argv, fileId, account, project, spinner) {
|
|
|
67
67
|
}
|
|
68
68
|
else if (response.status === 404) {
|
|
69
69
|
await wait();
|
|
70
|
-
continue;
|
|
71
70
|
}
|
|
72
71
|
else if (response.status === 500 &&
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
CURRENT_RETRY_ATTEMPTS_FOR_SERVER_UPDATES++;
|
|
72
|
+
currentRetryAttemptsForServerUpdates < maxRetryAttemptsForServerUpdates) {
|
|
73
|
+
currentRetryAttemptsForServerUpdates++;
|
|
76
74
|
await wait();
|
|
77
|
-
continue;
|
|
78
75
|
}
|
|
79
76
|
else {
|
|
80
77
|
logger.error(`Unexpected error from server while polling for deployment: ${response.status} ${response.statusText} ${textOrJson(await response.text())}`);
|
|
@@ -86,8 +83,8 @@ export async function pollDeployment(argv, fileId, account, project, spinner) {
|
|
|
86
83
|
};
|
|
87
84
|
}
|
|
88
85
|
export async function pollBuild(argv, endpoint, buildName, spinner) {
|
|
89
|
-
const
|
|
90
|
-
let
|
|
86
|
+
const MaxRetryAttemptsForServerUpdates = 5;
|
|
87
|
+
let CurrentRetryAttemptsForServerUpdates = 0;
|
|
91
88
|
for (let pollRetry = 0; pollRetry < settings.MAX_POLL_RETRIES; pollRetry++) {
|
|
92
89
|
spinner.suffixText = `(${pollRetry}/${settings.MAX_POLL_RETRIES})`;
|
|
93
90
|
const response = await fetch(`${endpoint}/v1/deployments/build/${buildName}`, {
|
|
@@ -114,14 +111,11 @@ export async function pollBuild(argv, endpoint, buildName, spinner) {
|
|
|
114
111
|
}
|
|
115
112
|
else if (response.status === 404) {
|
|
116
113
|
await wait();
|
|
117
|
-
continue;
|
|
118
114
|
}
|
|
119
115
|
else if (response.status === 500 &&
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
CURRENT_RETRY_ATTEMPTS_FOR_SERVER_UPDATES++;
|
|
116
|
+
CurrentRetryAttemptsForServerUpdates < MaxRetryAttemptsForServerUpdates) {
|
|
117
|
+
CurrentRetryAttemptsForServerUpdates++;
|
|
123
118
|
await wait();
|
|
124
|
-
continue;
|
|
125
119
|
}
|
|
126
120
|
else {
|
|
127
121
|
logger.error(JSON.stringify(await response.json(), null, 2), "Failed to upload to self-hosted build endpoint");
|