Skip to content

Commit

Permalink
[Dependencies] Replaced ts-node with tsx, removed dotenv (#3198)
Browse files Browse the repository at this point in the history
* refactor: ds-react uses tsx instead of ts-node

* refactor: ds-tailwind uses tsx

* refactor: Website backup and search uses tsx

* refactor: Test urls and rss-feed uses tsx

* refactor: Prop-updates uses tsx

* refactor: All website scripts uses tsx

* refactor: removed dotenv dependency from website

* feat: removed all dependencies to dotenv

* bug: Remove need for env in validate build script

* test: Create empty env file

* test: Scope env-file to build-dir

* bug: Fallback to empty env when no env exsists

* feat: Better error-messaging when fetching new icons

* Update @navikt/aksel-icons/package.json

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>

---------

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
  • Loading branch information
KenAJoh and HalvorHaugan authored Oct 8, 2024
1 parent f0e6c94 commit bdbd6c2
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 219 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/aksel-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: Install dependencies
run: yarn

- name: Create empty .env file (Can be removed when env-file-if-exists is implemented in node v22)
run: echo "" > ./aksel.nav.no/website/.env

- name: Build application
env:
SANITY_READ: ${{ secrets.SANITY_READ }}
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/aksel-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
yarn boot
yarn docgen
- name: Create empty .env file (Can be removed when env-file-if-exists is implemented in node v22)
run: echo "" > ./aksel.nav.no/website/.env

- name: Update sanity sync
env:
SANITY_WRITE: ${{ secrets.SANITY_WRITE }}
Expand Down Expand Up @@ -68,6 +71,9 @@ jobs:
- name: Tests
run: yarn workspace website test

- name: Create empty .env file (Can be removed when env-file-if-exists is implemented in node v22)
run: echo "" > ./aksel.nav.no/website/.env

- name: Build application
env:
SANITY_READ: ${{ secrets.SANITY_READ }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/backup-sanity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Install dependencies
run: cd aksel.nav.no/website && yarn

- name: Create empty .env file (Can be removed when env-file-if-exists is implemented in node v22)
run: echo "" > ./aksel.nav.no/website/.env

- name: Export dataset
env:
SANITY_READ: ${{ secrets.SANITY_READ }}
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
run: |
yarn boot
- name: Create empty .env file (Can be removed when env-file-if-exists is implemented in node v22)
run: echo "" > ./aksel.nav.no/website/.env

- name: Build application
env:
SANITY_READ: ${{ secrets.SANITY_READ }}
Expand Down
5 changes: 5 additions & 0 deletions @navikt/aksel-icons/config/figma/fetch-icons.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const file_key = "wEdyFjCQSBR3U7FvrMbPXa";

export const fetchIcons = async () => {
console.info("Fetching new icons from Figma...");
const data = await fetch(
`https://api.figma.com/v1/files/${file_key}/components`,
{
Expand All @@ -15,6 +16,10 @@ export const fetchIcons = async () => {
throw e.message;
});

if (data?.err) {
throw new Error(data.err);
}

if (!data?.meta?.components || data?.meta?.components.length === 0) {
throw new Error("Fant ingen publiserte ikoner");
}
Expand Down
3 changes: 1 addition & 2 deletions @navikt/aksel-icons/config/figma/index.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { config } from "dotenv";
import { existsSync, mkdirSync, readdirSync, rmSync, writeFileSync } from "fs";
import { resolve } from "path";
import { fetchDownloadUrls, fetchIcon, fetchIcons } from "./fetch-icons.mjs";
import { resolveName } from "./icon-name.mjs";
import { makeConfig } from "./make-configs.mjs";
import { paginate } from "./paginate.mjs";

config();
/* https://www.figma.com/file/wEdyFjCQSBR3U7FvrMbPXa/Core-Icons-Next?node-id=277%3A1221&t=mUJzFvnsceYYXNL5-0 */

const iconFolder = "./icons";
Expand All @@ -16,6 +14,7 @@ if (!process.env.FIGMA_TOKEN) {
}

async function main() {
console.info("Started icon-update from Figma");
let icons = await fetchIcons();

const totalIcons = icons.length;
Expand Down
4 changes: 2 additions & 2 deletions @navikt/aksel-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"update-metadata": "node config/metadata.js",
"write-packagejson": "echo '{\"type\": \"module\"}' > dist/react/esm/package.json",
"build": "yarn copy && yarn create-icons && concurrently \"tsc\" \"tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json && yarn write-packagejson\" && node config/cleanTypes.js && yarn update-metadata && yarn parse-svg",
"fetch-new:icons": "node config/figma/index.mjs",
"fetch-new:icons": "tsx --env-file=.env config/figma/index.mjs",
"zip:icons": "node config/zip.js",
"test": "vitest run",
"test:watch": "vitest watch"
Expand All @@ -73,7 +73,6 @@
"concurrently": "7.2.1",
"copyfiles": "^2.4.1",
"cross-zip-cli": "1.0.0",
"dotenv": "^10.0.0",
"fast-glob": "3.2.11",
"hast-util-select": "5.0.5",
"js-yaml": "^4.1.0",
Expand All @@ -83,6 +82,7 @@
"react": "^18.0.0",
"rehype-parse": "8.0.4",
"tsc-alias": "1.8.8",
"tsx": "^4.7.1",
"typescript": "^5.1.6",
"unified": "10.1.2",
"vitest": "^1.2.2"
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@
"./package.json": "./package.json"
},
"scripts": {
"docgen": "yarn ts-node ../../../scripts/docgen.ts",
"docgen": "yarn tsx ../../../scripts/docgen.ts",
"write-packagejson": "echo '{\"type\": \"module\"}' > esm/package.json",
"clean": "rimraf cjs esm",
"build": "concurrently \"tsc -p tsconfig.build.json\" \"tsc -p tsconfig.esm.json && tsc-alias -p tsconfig.esm.json && yarn write-packagejson\" ",
Expand Down Expand Up @@ -614,8 +614,8 @@
"react-router-dom": "^6.3.0",
"rimraf": "6.0.1",
"swr": "^1.1.2",
"ts-node": "^10.9.1",
"tsc-alias": "1.8.8",
"tsx": "^4.19.1",
"typescript": "^5.1.6",
"vitest": "^1.2.2"
},
Expand Down
4 changes: 2 additions & 2 deletions @navikt/core/tailwind/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"tailwind.config.d.ts"
],
"scripts": {
"build": "ts-node ./src",
"build": "yarn tsx ./src",
"test": "vitest run",
"test:watch": "vitest watch"
},
Expand All @@ -29,7 +29,7 @@
"color": "4.2.3",
"lodash": "^4.17.21",
"tailwindcss": "^3.3.3",
"ts-node": "^10.9.1",
"tsx": "^4.19.1",
"typescript": "^5.1.6",
"vitest": "^1.2.2"
},
Expand Down
24 changes: 12 additions & 12 deletions aksel.nav.no/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@
"cp:static": "copyfiles -E -u 1 '.next/static/**' .next/standalone/aksel.nav.no/website/.next/",
"cp:public": "copyfiles -E 'public/**' .next/standalone/aksel.nav.no/website/",
"cp:assets": "yarn cp:playroom && yarn cp:public && yarn cp:static",
"update:searchindex": "ts-node --project tsconfig.json ./scripts/create-index",
"update:searchindex": "yarn tsx --env-file=.env ./scripts/create-index",
"e2e": "yarn build && yarn start-server-and-test 'yarn start' http://localhost:3000 'yarn playwright'",
"e2e:full": "yarn build && ts-node ./e2e/genUrls.ts && FULL_TEST=true yarn start-server-and-test start http://localhost:3000 playwright",
"e2e:ci-full": "ts-node ./e2e/genUrls.ts && FULL_TEST=true yarn start-server-and-test start http://localhost:3000 playwright",
"update:rss": "ts-node --project tsconfig.tsnode.json ./scripts/generate-rss-feed",
"update:props": "ts-node --project tsconfig.tsnode.json ./scripts/update-props",
"update:tokens": "ts-node --project tsconfig.tsnode.json ./scripts/update-tokens",
"update:eksempler": "ts-node --project tsconfig.tsnode.json ./scripts/update-examples/update-sanity",
"validate:eksempler": "ts-node --project tsconfig.tsnode.json ./scripts/update-examples/validate",
"update:changelog": "ts-node --project tsconfig.tsnode.json ./scripts/changelog",
"e2e:full": "yarn build && yarn generate-testpaths && FULL_TEST=true yarn start-server-and-test start http://localhost:3000 playwright",
"e2e:ci-full": "yarn generate-testpaths && FULL_TEST=true yarn start-server-and-test start http://localhost:3000 playwright",
"update:rss": "yarn tsx --env-file=.env ./scripts/generate-rss-feed",
"update:props": "yarn tsx --env-file=.env ./scripts/update-props",
"update:tokens": "yarn tsx --env-file=.env ./scripts/update-tokens",
"update:eksempler": "yarn tsx --env-file=.env ./scripts/update-examples/update-sanity",
"validate:eksempler": "yarn tsx ./scripts/update-examples/validate",
"update:changelog": "yarn tsx --env-file=.env ./scripts/changelog",
"update:sanity": "yarn update:tokens && yarn update:props && yarn update:eksempler && yarn update:changelog",
"analyze": "cross-env ANALYZE=true yarn build",
"test": "vitest run -c config/vitest.config.ts",
"test:watch": "vitest watch -c config/vitest.config.ts",
"playwright": "playwright test",
"backup": "ts-node scripts/backup.js",
"backup": "yarn tsx --env-file=.env scripts/backup.ts",
"generate-testpaths": "yarn tsx --env-file=.env ./scripts/generate-testpaths.ts",
"watch:tw": "yarn tailwindcss -i ./components/styles/index.css -o ./dist/tw.css --watch"
},
"dependencies": {
Expand Down Expand Up @@ -91,7 +92,6 @@
"babel-loader": "^8.2.0",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.0",
"dotenv": "^10.0.0",
"jsdom": "^22.1.0",
"json5": "2.2.1",
"pino-pretty": "^10.0.0",
Expand All @@ -101,7 +101,7 @@
"rss": "^1.2.2",
"showdown": "^2.1.0",
"start-server-and-test": "^2.0.3",
"ts-node": "^10.9.1",
"tsx": "^4.19.1",
"typescript": "^5.1.6",
"vitest": "^1.2.2"
}
Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions aksel.nav.no/website/scripts/changelog.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { htmlToBlocks } from "@sanity/block-tools";
import { Schema } from "@sanity/schema";
import dotenv from "dotenv";
import fs from "fs";
import { JSDOM } from "jsdom";
import showdown from "showdown";
import { noCdnClient } from "../sanity/interface/client.server";

dotenv.config();

main();

export async function main() {
Expand Down Expand Up @@ -46,7 +43,7 @@ export async function main() {
.fields.find((field) => field.name === "body").type;

const blocks = htmlToBlocks(html, blockContentType, {
parseHtml: (htmlStr) => new JSDOM(htmlStr).window.document,
parseHtml: (htmlStr) => new JSDOM(htmlStr).window._document,
});
blocks.shift();

Expand Down
6 changes: 3 additions & 3 deletions aksel.nav.no/website/scripts/create-index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import dotenv from "dotenv";
import fs from "fs";
import { groupBy, omit } from "lodash";
import { allArticleDocuments } from "../sanity/config";
import { noCdnClient } from "../sanity/interface/client.server";

dotenv.config();

main();

async function main() {
await createIndex();
console.info(
"Successfully created searchindex and added it to public folder",
);
}

async function createIndex() {
Expand Down
4 changes: 0 additions & 4 deletions aksel.nav.no/website/scripts/generate-rss-feed.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import dotenv from "dotenv";
import fs from "fs";
import path from "path";
import RSS from "rss";
import { noCdnClient } from "../sanity/interface/client.server";

dotenv.config();
dotenv.config({ path: `.env.local` });

generateRssFeed();

async function generateRssFeed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import dotenv from "dotenv";
import fs from "fs";
import { sitemapPages } from "../sanity/interface/interface";

dotenv.config();

const token = process.env.SANITY_READ_NO_DRAFTS;

if (!token) {
console.error("Missing SANITY_READ_NO_DRAFTS");
process.exit(1);
}

/**
* Generate a list of urls for e2e tests
*/
sitemapPages(token)
.then((pages) =>
fs.writeFileSync(
Expand Down
3 changes: 0 additions & 3 deletions aksel.nav.no/website/scripts/update-examples/update-sanity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dotenv from "dotenv";
import { CodeExampleSchemaT } from "../../components/types";
import { noCdnClient } from "../../sanity/interface/client.server";
import { extractMetadata } from "./parts/extract-metadata";
Expand All @@ -7,8 +6,6 @@ import { parseCodeFiles } from "./parts/parse-code-files";
import { validateExamples } from "./parts/validate-examples";
import { RootDirectoriesT, rootDirectories } from "./types";

dotenv.config();

const isDryRun = process.argv.includes("--dry-run");

(async function () {
Expand Down
4 changes: 0 additions & 4 deletions aksel.nav.no/website/scripts/update-props.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import dotenv from "dotenv";
import fs from "fs";
import path from "path";
import { noCdnClient } from "../sanity/interface/client.server";

dotenv.config();
dotenv.config({ path: `.env.local` });

updateProps();

async function updateProps() {
Expand Down
5 changes: 1 addition & 4 deletions aksel.nav.no/website/scripts/update-tokens.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import dotenv from "dotenv";
import core from "@navikt/ds-css/tokens.json";
import tokens from "@navikt/ds-tokens/docs.json";
import { noCdnClient } from "../sanity/interface/client.server";

dotenv.config();

const allTokens: { title: string; kategori: string }[] = [
...Object.keys(tokens).map((x) => ({ title: x, kategori: "core" })),
...Object.keys(core).map((x) => ({ title: x, kategori: "comp" })),
Expand Down Expand Up @@ -47,7 +44,7 @@ export const updateTokens = async () => {

await transactionClient
.commit()
.then(() => console.info(`Updated tokens`))
.then(() => console.info(`Updated tokens!`))
.catch((e) => console.error(e.message));
};

Expand Down
6 changes: 0 additions & 6 deletions aksel.nav.no/website/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@
}
]
},
"ts-node": {
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "dom.iterable", "esnext", "ES2021.String"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules", "e2e", "./scripts/**"]
}
26 changes: 0 additions & 26 deletions aksel.nav.no/website/tsconfig.tsnode.json

This file was deleted.

Loading

0 comments on commit bdbd6c2

Please sign in to comment.