@entur/function-tools 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -1,2 +1,2 @@
1
- # firebase-tools
2
- Ekstra verktøy for firebase
1
+ # function-tools
2
+ Ekstra verktøy for firebase functions
@@ -5,7 +5,7 @@ import { registerStart } from '../lib/commands/start.js';
5
5
  import { registerUnusedExports } from '../lib/commands/unusedExports.js';
6
6
 
7
7
  const program = new Command();
8
- program.name("entur-firebase").description("A multi-command CLI built with commander").version("0.0.1").option("-v, --verbose", "Enable verbose output");
8
+ program.name("entur-firebase").description("A multi-command CLI built with commander").version("0.0.3").option("-v, --verbose", "Enable verbose output");
9
9
  registerBuild(program);
10
10
  registerDeploy(program);
11
11
  registerStart(program);
@@ -3,12 +3,12 @@ import { flattenDependencies, harmonizeDependencies, calculateDependencies } fro
3
3
  import { cleanDir } from '../utils/fs.js';
4
4
  import { readPackageJSON } from '../utils/packageJSON.js';
5
5
  import { getWorkspacePackageNames } from '../utils/workspace.js';
6
- import { createContext } from './utils.js';
6
+ import { resolveProjectConfig } from './utils.js';
7
7
 
8
8
  function registerBuild(program) {
9
9
  program.command("build").description("Build the project").option("-o, --output-dir <dir>", "Output directory").action(async (options)=>{
10
10
  try {
11
- const { packageRoot, packageJSON, outputDir, pnpmWorkspaceYAML } = await createContext(options);
11
+ const { packageRoot, packageJSON, outputDir, pnpmWorkspaceYAML } = await resolveProjectConfig(options);
12
12
  const { name, exports: exports$1 } = await readPackageJSON(packageJSON);
13
13
  console.log("🧹 Cleaning dist folder");
14
14
  await cleanDir(outputDir);
@@ -6,13 +6,13 @@ import { getFirebaseJSON, writeFirebaseJSON } from '../utils/firebase.js';
6
6
  import { cleanDir, writeJSON } from '../utils/fs.js';
7
7
  import { readPackageJSON, getPackageName, writePackageJSON } from '../utils/packageJSON.js';
8
8
  import { getWorkspacePackageNames } from '../utils/workspace.js';
9
- import { createContext } from './utils.js';
9
+ import { resolveProjectConfig } from './utils.js';
10
10
 
11
11
  function registerDeploy(program) {
12
12
  program.command("deploy").description("Deploy the project").option("-o, --output-dir <dir>", "Output directory").option("-P, --project <project id or alias>", "Project id or alias").action(async (options)=>{
13
13
  try {
14
- const context = await createContext(options);
15
- await deploy(context);
14
+ const projectConfig = await resolveProjectConfig(options);
15
+ await deploy(projectConfig);
16
16
  } catch (error) {
17
17
  console.error(error);
18
18
  process.exit(1);
@@ -5,13 +5,13 @@ import { getFirebaseJSON, writeFirebaseJSON } from '../utils/firebase.js';
5
5
  import { cleanDir, writeJSON } from '../utils/fs.js';
6
6
  import { readPackageJSON, getPackageName, writePackageJSON } from '../utils/packageJSON.js';
7
7
  import { getWorkspacePackageNames } from '../utils/workspace.js';
8
- import { createContext } from './utils.js';
8
+ import { resolveProjectConfig } from './utils.js';
9
9
 
10
10
  function registerStart(program) {
11
11
  program.command("start").description("Start function emulator").option("-o, --output-dir <dir>", "Output directory").option("-P, --project <project id or alias>", "Project id or alias").action(async (options)=>{
12
12
  try {
13
- const context = await createContext(options);
14
- await start(context);
13
+ const projectConfig = await resolveProjectConfig(options);
14
+ await start(projectConfig);
15
15
  } catch (error) {
16
16
  console.error(error);
17
17
  process.exit(1);
@@ -9,26 +9,27 @@ import { createResolver } from '../importExports/resolve.js';
9
9
  import { createResolveImport } from '../importExports/resolveImports.js';
10
10
  import { createReadFileDependencies, extractUnusedExports } from '../importExports/unused.js';
11
11
  import { createCache } from '../importExports/utils.js';
12
- import { createContext } from './utils.js';
13
12
 
14
13
  function registerUnusedExports(program) {
15
- program.command("unused-exports").description("Check for unused exports").action(async ()=>{
14
+ program.command("unused-exports").description("Check for unused exports").option("-i, --include <pattern...>", "Include glob pattern", [
15
+ "**/*.ts"
16
+ ]).option("-e, --exclude <numbers...>", "Excude glob pattern", [
17
+ "**/node_modules"
18
+ ]).option("--ignore <numbers...>", "Ignore glob pattern", []).option("--extensions <numbers...>", "File extensions to resolve", [
19
+ ".ts"
20
+ ]).action(async (options)=>{
16
21
  try {
17
- const context = await createContext();
18
- await unusedExports([
19
- "**/*.+(ts|tsx)"
20
- ], [], {
21
- extensions: [
22
- ".ts"
23
- ]
24
- }, context);
22
+ const cwd = process.cwd();
23
+ await unusedExports(options.include, options.ignore, options.exclude, {
24
+ extensions: options.extensions
25
+ }, cwd);
25
26
  } catch (error) {
26
27
  console.error(error);
27
28
  process.exit(1);
28
29
  }
29
30
  });
30
31
  }
31
- async function unusedExports(patterns, ignorePatterns, resolverOptions, { cwd }) {
32
+ async function unusedExports(patterns, ignorePatterns, excludePatterns, resolverOptions, cwd) {
32
33
  const resolver = createResolver({
33
34
  conditionNames: [
34
35
  "import",
@@ -40,15 +41,10 @@ async function unusedExports(patterns, ignorePatterns, resolverOptions, { cwd })
40
41
  });
41
42
  const resolveImport = createResolveImport(resolver, getFileExports, getFileProxyExports);
42
43
  const readFileDependencies = createReadFileDependencies(getFileImports, getFileExports, resolveImport);
43
- const exclude = [
44
- "**/node_modules",
45
- "tools/createPackage/template",
46
- "tools/dependency/mocks"
47
- ];
48
44
  const fileDependencies = [];
49
45
  for await (const filePath of glob(patterns, {
50
46
  cwd,
51
- exclude
47
+ exclude: excludePatterns
52
48
  })){
53
49
  fileDependencies.push(await readFileDependencies(join(cwd, filePath)));
54
50
  }
@@ -0,0 +1,18 @@
1
+ type Options = {
2
+ outputDir?: string;
3
+ project?: string;
4
+ cwd?: string;
5
+ };
6
+ type ProjectConfig = {
7
+ pnpmWorkspaceYAML: URL;
8
+ packageJSON: URL;
9
+ outputDir: URL;
10
+ packageRoot: URL;
11
+ projectRoot: URL;
12
+ projectAlias: string;
13
+ projectId: string;
14
+ };
15
+ declare function resolveProjectConfig({ outputDir, project, cwd, }?: Options): Promise<ProjectConfig>;
16
+
17
+ export { resolveProjectConfig };
18
+ export type { ProjectConfig };
@@ -2,8 +2,7 @@ import { pathToFileURL } from 'node:url';
2
2
  import { findUp } from 'find-up-simple';
3
3
  import { readJSON } from '../utils/fs.js';
4
4
 
5
- async function createContext({ outputDir = "dist", project } = {}) {
6
- const cwd = process.cwd();
5
+ async function resolveProjectConfig({ outputDir = "dist", project, cwd = process.cwd() } = {}) {
7
6
  const [pnpmWorkspacePath, packageJSONPath, firebaseRCPath] = await Promise.all([
8
7
  findUp("pnpm-workspace.yaml", {
9
8
  cwd
@@ -36,8 +35,7 @@ async function createContext({ outputDir = "dist", project } = {}) {
36
35
  packageRoot: new URL("./", packageJSONUrl),
37
36
  projectRoot: new URL("./", pnpmWorkspaceYAML),
38
37
  projectAlias,
39
- projectId,
40
- cwd
38
+ projectId
41
39
  };
42
40
  }
43
41
  function getProjectAliasAndId({ default: defaultProjectId, ...projects }, project) {
@@ -70,4 +68,4 @@ function getProjectAliasAndId({ default: defaultProjectId, ...projects }, projec
70
68
  throw new Error(`No project with alias or id ${project} found in .firebaserc`);
71
69
  }
72
70
 
73
- export { createContext };
71
+ export { resolveProjectConfig };
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
+ export { ProjectConfig, resolveProjectConfig } from './commands/utils.js';
1
2
  export { Export, getExports } from './importExports/exports.js';
2
3
  export { Import, getImports } from './importExports/imports.js';
package/lib/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ export { resolveProjectConfig } from './commands/utils.js';
1
2
  export { getExports } from './importExports/exports.js';
2
3
  export { getImports } from './importExports/imports.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@entur/function-tools",
3
3
  "type": "module",
4
- "version": "0.0.1",
4
+ "version": "0.0.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },