diff --git a/packages/@cdktf/commons/package.json b/packages/@cdktf/commons/package.json index e7811f9a08..5fdec8b4b3 100644 --- a/packages/@cdktf/commons/package.json +++ b/packages/@cdktf/commons/package.json @@ -44,15 +44,16 @@ "cross-spawn": "7.0.6", "follow-redirects": "1.15.9", "fs-extra": "11.2.0", - "is-valid-domain": "0.1.6", "log4js": "6.9.1", "strip-ansi": "6.0.1", - "uuid": "9.0.1" + "uuid": "9.0.1", + "validator": "13.12.0" }, "devDependencies": { "@types/follow-redirects": "1.14.4", "@types/fs-extra": "11.0.4", "@types/uuid": "9.0.8", + "@types/validator": "13.12.2", "@typescript-eslint/eslint-plugin": "4.33.0", "@typescript-eslint/parser": "4.33.0", "eslint-config-prettier": "8.10.0", diff --git a/packages/@cdktf/commons/src/terraform-module.test.ts b/packages/@cdktf/commons/src/terraform-module.test.ts new file mode 100644 index 0000000000..c8e7c20ee8 --- /dev/null +++ b/packages/@cdktf/commons/src/terraform-module.test.ts @@ -0,0 +1,30 @@ +/** + * Copyright (c) HashiCorp, Inc. + * SPDX-License-Identifier: MPL-2.0 + */ + +import { isRegistryModule } from "./terraform-module"; + +describe("terraform-module", () => { + describe.each` + source | expected + ${"hashicorp/consul/aws"} | ${true} + ${"hashicorp/consul/aws//foo"} | ${false} + ${"./consul"} | ${false} + ${"git@github.com:hashicorp/example.git"} | ${false} + ${"github.com/hashicorp/example"} | ${false} + ${"github.com/hashicorp/terraform-cidr-subnets"} | ${false} + ${"bitbucket.org/hashicorp/terraform-consul-aws"} | ${false} + ${"foo/var/baz/qux"} | ${false} + ${"foo.com/var/baz"} | ${true} + ${".foo.com/var/baz"} | ${false} + ${"f-o-o.com/var/baz"} | ${true} + ${"foo.com/var/baz/canz"} | ${true} + ${"example.com/awesomecorp/network/happycloud//examples/foo"} | ${false} + ${"www.googleapis.com/storage/v1/BUCKET_NAME/PATH_TO_MODULE"} | ${false} + `("isRegistryModule($source)", ({ source, expected }) => { + it(`expects ${expected}`, () => { + expect(isRegistryModule(source)).toBe(expected); + }); + }); +}); diff --git a/packages/@cdktf/commons/src/terraform-module.ts b/packages/@cdktf/commons/src/terraform-module.ts index 0aad128d1e..e231efca9d 100644 --- a/packages/@cdktf/commons/src/terraform-module.ts +++ b/packages/@cdktf/commons/src/terraform-module.ts @@ -1,6 +1,6 @@ // Copyright (c) HashiCorp, Inc // SPDX-License-Identifier: MPL-2.0 -import isValidDomain from "is-valid-domain"; +import { isFQDN } from "validator"; // Logic from https://github.com/hashicorp/terraform/blob/e09b831f6ee35d37b11b8dcccd3a6d6f6db5e5ff/internal/addrs/module_source.go#L198 export function isRegistryModule(source: string) { @@ -15,7 +15,7 @@ export function isRegistryModule(source: string) { return false; } - if (parts.length === 4 && !isValidDomain(parts[0])) { + if (parts.length === 4 && !isFQDN(parts[0])) { return false; } diff --git a/yarn.lock b/yarn.lock index 7cb395a669..321dd9b5fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2405,6 +2405,11 @@ resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-9.0.8.tgz#7545ba4fc3c003d6c756f651f3bf163d8f0f29ba" integrity sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA== +"@types/validator@13.12.2": + version "13.12.2" + resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.12.2.tgz#760329e756e18a4aab82fc502b51ebdfebbe49f5" + integrity sha512-6SlHBzUW8Jhf3liqrGGXyTJSIFe4nqlJ5A5KaMZ2l/vbM3Wh3KSybots/wfWVzNLK4D1NZluDlSQIbIEPx6oyA== + "@types/wrap-ansi@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/wrap-ansi/-/wrap-ansi-3.0.0.tgz#18b97a972f94f60a679fd5c796d96421b9abb9fd" @@ -6930,13 +6935,6 @@ is-upper-case@^2.0.2: dependencies: tslib "^2.0.3" -is-valid-domain@0.1.6: - version "0.1.6" - resolved "https://registry.yarnpkg.com/is-valid-domain/-/is-valid-domain-0.1.6.tgz#3c85469d2938f170c8f82ce6e52df8ad9fca8105" - integrity sha512-ZKtq737eFkZr71At8NxOFcP9O1K89gW3DkdrGMpp1upr/ueWjj+Weh4l9AI4rN0Gt8W2M1w7jrG2b/Yv83Ljpg== - dependencies: - punycode "^2.1.1" - is-weakmap@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.2.tgz#bf72615d649dfe5f699079c54b83e47d1ae19cfd" @@ -12230,6 +12228,11 @@ validate-npm-package-name@^5.0.0: dependencies: builtins "^5.0.0" +validator@13.12.0: + version "13.12.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-13.12.0.tgz#7d78e76ba85504da3fee4fd1922b385914d4b35f" + integrity sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg== + w3c-hr-time@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.2.tgz#0a89cdf5cc15822df9c360543676963e0cc308cd"