diff --git a/package-lock.json b/package-lock.json index a8f1c7aa..aa5fc70e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7387,7 +7387,6 @@ "version": "7.20.0", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.0.tgz", "integrity": "sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==", - "dev": true, "dependencies": { "@babel/parser": "^7.20.7", "@babel/types": "^7.20.7", @@ -7400,7 +7399,6 @@ "version": "7.6.4", "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.4.tgz", "integrity": "sha512-tFkciB9j2K755yrTALxD44McOrk+gfpIpvC3sxHjRawj6PfnQxrse4Clq5y/Rq+G3mrBurMax/lG8Qn2t9mSsg==", - "dev": true, "dependencies": { "@babel/types": "^7.0.0" } @@ -7418,7 +7416,6 @@ "version": "7.4.1", "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.1.tgz", "integrity": "sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==", - "dev": true, "dependencies": { "@babel/parser": "^7.1.0", "@babel/types": "^7.0.0" @@ -7428,7 +7425,6 @@ "version": "7.18.3", "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.18.3.tgz", "integrity": "sha512-1kbcJ40lLB7MHsj39U4Sh1uTd2E7rLEa79kmDpI6cy+XiXsteB3POdQomoq4FxszMrO3ZYchkhYJw7A2862b3w==", - "dev": true, "dependencies": { "@babel/types": "^7.3.0" } @@ -9401,12 +9397,33 @@ "integrity": "sha512-qrPaCSo9c8RHNRHIotaufGbuOBN8rtdC4QrrFFc43vyWCCz7Kl7GL1PGaXtMGQZUXrkCjNEgxDfmAuAabr/rlw==", "dev": true }, + "node_modules/babel-plugin-transform-import-meta": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-import-meta/-/babel-plugin-transform-import-meta-2.2.0.tgz", + "integrity": "sha512-+DNF2SJAj2Pd0b1sObz+hyzNgUlI9DccPtMcF7ulMM0BxPrMF83ERjvPQwcQ9FRFSddWcC7DOw0FuyWgkQRoqg==", + "dependencies": { + "@babel/template": "^7.4.4", + "tslib": "^2.4.0" + }, + "peerDependencies": { + "@babel/core": "^7.10.0" + } + }, "node_modules/babel-plugin-transform-react-remove-prop-types": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.24.tgz", "integrity": "sha512-eqj0hVcJUR57/Ug2zE1Yswsw4LhuqqHhD+8v120T1cl3kjg76QwtyBrdIk4WVwK+lAhBJVYCd/v+4nc4y+8JsA==", "dev": true }, + "node_modules/babel-plugin-transform-vite-meta-env": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-vite-meta-env/-/babel-plugin-transform-vite-meta-env-1.0.3.tgz", + "integrity": "sha512-eyfuDEXrMu667TQpmctHeTlJrZA6jXYHyEJFjcM0yEa60LS/LXlOg2PBbMb8DVS+V9CnTj/j9itdlDVMcY2zEg==", + "dependencies": { + "@babel/runtime": "^7.13.9", + "@types/babel__core": "^7.1.12" + } + }, "node_modules/babel-preset-current-node-syntax": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz", @@ -31885,6 +31902,8 @@ "@sanity-codegen/types": "^1.0.0-alpha.34", "babel-merge": "^3.0.0", "babel-plugin-css-modules-transform": "^1.6.2", + "babel-plugin-transform-import-meta": "^2.2.0", + "babel-plugin-transform-vite-meta-env": "^1.0.3", "jsdom": "^21.0.0", "jsdom-global": "^3.0.2", "prettier": "^2.8.3" @@ -36783,6 +36802,8 @@ "@sanity-codegen/types": "^1.0.0-alpha.34", "babel-merge": "^3.0.0", "babel-plugin-css-modules-transform": "^1.6.2", + "babel-plugin-transform-import-meta": "^2.2.0", + "babel-plugin-transform-vite-meta-env": "^1.0.3", "jsdom": "^21.0.0", "jsdom-global": "^3.0.2", "prettier": "^2.8.3", @@ -37614,7 +37635,6 @@ "version": "7.20.0", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.0.tgz", "integrity": "sha512-+n8dL/9GWblDO0iU6eZAwEIJVr5DWigtle+Q6HLOrh/pdbXOhOtqzq8VPPE2zvNJzSKY4vH/z3iT3tn0A3ypiQ==", - "dev": true, "requires": { "@babel/parser": "^7.20.7", "@babel/types": "^7.20.7", @@ -37627,7 +37647,6 @@ "version": "7.6.4", "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.4.tgz", "integrity": "sha512-tFkciB9j2K755yrTALxD44McOrk+gfpIpvC3sxHjRawj6PfnQxrse4Clq5y/Rq+G3mrBurMax/lG8Qn2t9mSsg==", - "dev": true, "requires": { "@babel/types": "^7.0.0" } @@ -37645,7 +37664,6 @@ "version": "7.4.1", "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.1.tgz", "integrity": "sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g==", - "dev": true, "requires": { "@babel/parser": "^7.1.0", "@babel/types": "^7.0.0" @@ -37655,7 +37673,6 @@ "version": "7.18.3", "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.18.3.tgz", "integrity": "sha512-1kbcJ40lLB7MHsj39U4Sh1uTd2E7rLEa79kmDpI6cy+XiXsteB3POdQomoq4FxszMrO3ZYchkhYJw7A2862b3w==", - "dev": true, "requires": { "@babel/types": "^7.3.0" } @@ -39266,12 +39283,30 @@ "integrity": "sha512-qrPaCSo9c8RHNRHIotaufGbuOBN8rtdC4QrrFFc43vyWCCz7Kl7GL1PGaXtMGQZUXrkCjNEgxDfmAuAabr/rlw==", "dev": true }, + "babel-plugin-transform-import-meta": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-import-meta/-/babel-plugin-transform-import-meta-2.2.0.tgz", + "integrity": "sha512-+DNF2SJAj2Pd0b1sObz+hyzNgUlI9DccPtMcF7ulMM0BxPrMF83ERjvPQwcQ9FRFSddWcC7DOw0FuyWgkQRoqg==", + "requires": { + "@babel/template": "^7.4.4", + "tslib": "^2.4.0" + } + }, "babel-plugin-transform-react-remove-prop-types": { "version": "0.4.24", "resolved": "https://registry.npmjs.org/babel-plugin-transform-react-remove-prop-types/-/babel-plugin-transform-react-remove-prop-types-0.4.24.tgz", "integrity": "sha512-eqj0hVcJUR57/Ug2zE1Yswsw4LhuqqHhD+8v120T1cl3kjg76QwtyBrdIk4WVwK+lAhBJVYCd/v+4nc4y+8JsA==", "dev": true }, + "babel-plugin-transform-vite-meta-env": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-vite-meta-env/-/babel-plugin-transform-vite-meta-env-1.0.3.tgz", + "integrity": "sha512-eyfuDEXrMu667TQpmctHeTlJrZA6jXYHyEJFjcM0yEa60LS/LXlOg2PBbMb8DVS+V9CnTj/j9itdlDVMcY2zEg==", + "requires": { + "@babel/runtime": "^7.13.9", + "@types/babel__core": "^7.1.12" + } + }, "babel-preset-current-node-syntax": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.0.1.tgz", diff --git a/packages/cli/src/commands/codegen.test.ts b/packages/cli/src/commands/codegen.test.ts index 9693892c..5932c174 100644 --- a/packages/cli/src/commands/codegen.test.ts +++ b/packages/cli/src/commands/codegen.test.ts @@ -51,7 +51,7 @@ describe('codegen command', () => { "Converting queries to typescript…", "Converted 2 queries to TypeScript", "Writing query types output…", - "Wrote query types output to ", + "Wrote types to ", ] `); diff --git a/packages/extractor/package.json b/packages/extractor/package.json index 6eff75f0..d68a0cf2 100644 --- a/packages/extractor/package.json +++ b/packages/extractor/package.json @@ -48,6 +48,8 @@ "@sanity-codegen/types": "^1.0.0-alpha.34", "babel-merge": "^3.0.0", "babel-plugin-css-modules-transform": "^1.6.2", + "babel-plugin-transform-import-meta": "^2.2.0", + "babel-plugin-transform-vite-meta-env": "^1.0.3", "jsdom": "^21.0.0", "jsdom-global": "^3.0.2", "prettier": "^2.8.3" diff --git a/packages/extractor/src/default-babel-options.ts b/packages/extractor/src/default-babel-options.ts index f920e18f..60cd98d3 100644 --- a/packages/extractor/src/default-babel-options.ts +++ b/packages/extractor/src/default-babel-options.ts @@ -24,6 +24,10 @@ export const defaultBabelOptions = { plugins: [ // used to resolve css module imports that are allowed in sanity projects 'css-modules-transform', + // used to convert import.meta.env.VAR + 'babel-plugin-transform-vite-meta-env', + // used to convert `import.meta.url` + 'babel-plugin-transform-import-meta', '@babel/plugin-proposal-class-properties', '@babel/plugin-proposal-numeric-separator', '@babel/plugin-proposal-optional-chaining',