@atomicsmash/smash-config 0.0.1 → 1.0.0

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.
@@ -0,0 +1,16 @@
1
+ import { Options } from "sass";
2
+ export type SCSSAliases = {
3
+ loadPaths?: Options<"async">["loadPaths"];
4
+ importers?: Options<"async">["importers"];
5
+ };
6
+ export type SmashConfig = {
7
+ projectName: string;
8
+ themePath: string;
9
+ themeFolderName?: string;
10
+ assetsOutputFolder?: string;
11
+ npmInstallPaths?: string[];
12
+ composerInstallPaths?: string[];
13
+ scssAliases?: SCSSAliases;
14
+ };
15
+ export { getSmashConfig } from "./utils.js";
16
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,MAAM,WAAW,GAAG;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,CAAC;CAC1C,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEF,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { getSmashConfig } from "./utils.js";
@@ -0,0 +1,3 @@
1
+ import type { SmashConfig } from "./index.js";
2
+ export declare function getSmashConfig(): Promise<Required<SmashConfig> | null>;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,YAAY,CAAC;AA4B3D,wBAAsB,cAAc,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,CAoE5E"}
package/dist/utils.js ADDED
@@ -0,0 +1,94 @@
1
+ import { normalize, resolve } from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+ import { cosmiconfig } from "cosmiconfig";
4
+ const getDefaultSCSSAliases = (themePath) => ({
5
+ importers: [
6
+ {
7
+ findFileUrl(url) {
8
+ if (!url.startsWith("sitecss:"))
9
+ return null;
10
+ const pathname = url.substring(8);
11
+ return pathToFileURL(`${resolve(process.cwd(), themePath, "src/styles")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
12
+ },
13
+ },
14
+ {
15
+ findFileUrl(url) {
16
+ if (!url.startsWith("launchpad:"))
17
+ return null;
18
+ const pathname = url.substring(10);
19
+ return pathToFileURL(`${resolve(process.cwd(), themePath, "../launchpad/src/styles")}${pathname.startsWith("/") ? pathname : `/${pathname}`}`);
20
+ },
21
+ },
22
+ ],
23
+ });
24
+ export async function getSmashConfig() {
25
+ const explorer = cosmiconfig("smash");
26
+ const config = await explorer
27
+ .load(resolve(process.cwd(), "smash.config.ts"))
28
+ .then((result) => {
29
+ if (!result || result.isEmpty) {
30
+ throw new Error("Return default config.");
31
+ }
32
+ const config = result.config;
33
+ if (isValidSmashConfig(config)) {
34
+ const fullConfig = {
35
+ scssAliases: getDefaultSCSSAliases(config.themePath),
36
+ themeFolderName: config.projectName,
37
+ ...config,
38
+ // Normalize and resolve paths to cwd.
39
+ npmInstallPaths: config.npmInstallPaths?.map((path) => {
40
+ return normalize(resolve(process.cwd(), path));
41
+ }) ?? [],
42
+ composerInstallPaths: config.composerInstallPaths?.map((path) => {
43
+ return normalize(resolve(process.cwd(), path));
44
+ }) ?? [],
45
+ assetsOutputFolder: config.assetsOutputFolder
46
+ ? normalize(config.assetsOutputFolder)
47
+ : "dist",
48
+ };
49
+ return fullConfig;
50
+ }
51
+ throw new Error("Return default config.");
52
+ })
53
+ .catch(async () => {
54
+ const { themeName, themePath } = await import("dotenv")
55
+ .then((dotenv) => {
56
+ dotenv.config();
57
+ const themeName = process.env.THEME_NAME ?? process.env.npm_package_config_theme_name;
58
+ const themePath = process.env.THEME_PATH ?? process.env.npm_package_config_theme_path;
59
+ return {
60
+ themeName,
61
+ themePath,
62
+ };
63
+ })
64
+ .catch(() => {
65
+ return {
66
+ themeName: false,
67
+ themePath: false,
68
+ };
69
+ });
70
+ if (!themeName || !themePath) {
71
+ return null;
72
+ }
73
+ console.warn("Using env vars for theme name and path is deprecated and will be removed in a future version. Create a smash.config.ts file with the relevant properties in it instead.");
74
+ const defaultConfig = {
75
+ projectName: themeName,
76
+ themePath,
77
+ themeFolderName: themeName,
78
+ assetsOutputFolder: "dist",
79
+ npmInstallPaths: [],
80
+ composerInstallPaths: [],
81
+ scssAliases: getDefaultSCSSAliases(themePath),
82
+ };
83
+ return defaultConfig;
84
+ });
85
+ return config;
86
+ }
87
+ function isValidSmashConfig(config) {
88
+ return (typeof config === "object" &&
89
+ config !== null &&
90
+ "projectName" in config &&
91
+ typeof config.projectName === "string" &&
92
+ "themePath" in config &&
93
+ typeof config.themePath === "string");
94
+ }
package/package.json CHANGED
@@ -1,10 +1,46 @@
1
1
  {
2
- "name": "@atomicsmash/smash-config",
3
- "version": "0.0.1",
4
- "description": "OIDC trusted publishing setup package for @atomicsmash/smash-config",
5
- "keywords": [
6
- "oidc",
7
- "trusted-publishing",
8
- "setup"
9
- ]
2
+ "name": "@atomicsmash/smash-config",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "description": "",
6
+ "keywords": [],
7
+ "homepage": "https://www.atomicsmash.co.uk/",
8
+ "license": "GPL-3.0-or-later",
9
+ "author": {
10
+ "name": "Atomic Smash",
11
+ "email": "npm@atomicsmash.co.uk",
12
+ "url": "https://www.atomicsmash.co.uk/"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/AtomicSmash/packages",
17
+ "directory": "packages/smash-config"
18
+ },
19
+ "files": [
20
+ "./dist/**/*"
21
+ ],
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "scripts": {
28
+ "dev": "tsc --build --watch tsconfig.build.json",
29
+ "build": "npm-run-all clean compile",
30
+ "clean": "del-cli ./dist/ *.tsbuildinfo",
31
+ "compile": "tsc --build tsconfig.build.json",
32
+ "test": "TZ=\"Europe/Istanbul\" vitest run",
33
+ "test:ui": "TZ=\"Europe/Istanbul\" vitest --ui",
34
+ "test:coverage": "TZ=\"Europe/Istanbul\" vitest run --coverage",
35
+ "lint": "run-p lint:*",
36
+ "lint:eslint": "eslint --cache --cache-location ./node_modules/.cache/eslint . --ext .js,.ts,.jsx,.tsx",
37
+ "lint:types": "tsc"
38
+ },
39
+ "peerDependencies": {
40
+ "dotenv": "^17.2.3",
41
+ "sass": "^1.97.0"
42
+ },
43
+ "dependencies": {
44
+ "cosmiconfig": "^9.0.0"
45
+ }
10
46
  }
package/README.md DELETED
@@ -1,45 +0,0 @@
1
- # @atomicsmash/smash-config
2
-
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@atomicsmash/smash-config`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**