Procházet zdrojové kódy

typescriptize next.config.utils.ts

Yuki Takei před 3 roky
rodič
revize
441096bb9a
1 změnil soubory, kde provedl 14 přidání a 11 odebrání
  1. 14 11
      packages/app/src/utils/next.config.utils.ts

+ 14 - 11
packages/app/src/utils/next.config.utils.js → packages/app/src/utils/next.config.utils.ts

@@ -1,16 +1,19 @@
 // workaround by https://github.com/martpie/next-transpile-modules/issues/143#issuecomment-817467144
 
-const fs = require('fs');
-const path = require('path');
+import fs from 'fs';
+import path from 'path';
 
 const nodeModulesPath = path.resolve(__dirname, '../../../../node_modules');
 
+type Opts = {
+  ignorePackageNames: string[],
+}
 
-const defaultOpts = { ignorePackageNames: [] };
+const defaultOpts: Opts = { ignorePackageNames: [] };
 
 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-export const listScopedPackages = (scopes, opts = defaultOpts) => {
-  const scopedPackages = [];
+export const listScopedPackages = (scopes: string[], opts = defaultOpts) => {
+  const scopedPackages: string[] = [];
 
   fs.readdirSync(nodeModulesPath)
     .filter(name => scopes.includes(name))
@@ -18,13 +21,13 @@ export const listScopedPackages = (scopes, opts = defaultOpts) => {
       fs.readdirSync(path.resolve(nodeModulesPath, scope))
         .filter(name => !name.startsWith('.'))
         .forEach((folderName) => {
-          const { name, ignoreTranspileModules } = require(path.resolve(
+          const { name } = require(path.resolve(
             nodeModulesPath,
             scope,
             folderName,
             'package.json',
           ));
-          if (!ignoreTranspileModules && !opts.ignorePackageNames.includes(name)) {
+          if (!opts.ignorePackageNames.includes(name)) {
             scopedPackages.push(name);
           }
         });
@@ -34,19 +37,19 @@ export const listScopedPackages = (scopes, opts = defaultOpts) => {
 };
 
 // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
-export const listPrefixedPackages = (prefixes, opts = defaultOpts) => {
-  const prefixedPackages = [];
+export const listPrefixedPackages = (prefixes: string[], opts = defaultOpts) => {
+  const prefixedPackages: string[] = [];
 
   fs.readdirSync(nodeModulesPath)
     .filter(name => prefixes.some(prefix => name.startsWith(prefix)))
     .filter(name => !name.startsWith('.'))
     .forEach((folderName) => {
-      const { name, ignoreTranspileModules } = require(path.resolve(
+      const { name } = require(path.resolve(
         nodeModulesPath,
         folderName,
         'package.json',
       ));
-      if (!ignoreTranspileModules && !opts.ignorePackageNames.includes(name)) {
+      if (!opts.ignorePackageNames.includes(name)) {
         prefixedPackages.push(name);
       }
     });