Skip to content

Commit

Permalink
Always use cwd for install/config setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Sep 18, 2024
1 parent 8744254 commit 4c29062
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 21 deletions.
2 changes: 2 additions & 0 deletions programs/create/steps/install-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export async function installDependencies(
projectPath: string,
projectName: string
) {
// In this case the node_modules directory is always created in the
// root of projectPath so no need to use cwd.
const nodeModulesPath = path.join(projectPath, 'node_modules')

const command = await utils.getInstallCommand()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ function getInstallArgs() {
return ['install' /*, '--silent' */]
}

export async function installDependencies(projectPath: string) {
const nodeModulesPath = path.join(projectPath, 'node_modules')
export async function installDependencies(_projectPath: string) {
const nodeModulesPath = path.join(process.cwd(), 'node_modules')

const command = await getInstallCommand()
const dependenciesArgs = getInstallArgs()
Expand All @@ -42,7 +42,7 @@ export async function installDependencies(projectPath: string) {

try {
// Change to the project directory
process.chdir(projectPath)
process.chdir(process.cwd())

// Create the node_modules directory if it doesn't exist
await fs.promises.mkdir(nodeModulesPath, {recursive: true})
Expand Down
2 changes: 1 addition & 1 deletion programs/develop/webpack/plugin-css/css-tools/less.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function maybeUseLess(
try {
require.resolve('less-loader')
} catch (e) {
const projectName = require(path.join(projectPath, 'package.json')).name
const projectName = require(path.join(process.cwd(), 'package.json')).name

const lessDependencies = ['less', 'less-loader', 'resolve-url-loader']

Expand Down
4 changes: 2 additions & 2 deletions programs/develop/webpack/plugin-css/css-tools/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function isUsingPostCss(projectPath: string): boolean {
}

for (const configFile of postCssConfigFiles) {
if (fs.existsSync(path.join(projectPath, configFile))) {
if (fs.existsSync(path.join(process.cwd(), configFile))) {
if (!userMessageDelivered) {
if (process.env.EXTENSION_ENV === 'development') {
console.log(messages.isUsingIntegration(manifestName, 'PostCSS'))
Expand Down Expand Up @@ -88,7 +88,7 @@ export async function maybeUsePostCss(
try {
require.resolve('postcss-loader')
} catch (e) {
const projectName = require(path.join(projectPath, 'package.json')).name
const projectName = require(path.join(process.cwd(), 'package.json')).name

// SASS and LESS will install PostCSS as a dependency
// so we don't need to check for it here.
Expand Down
2 changes: 1 addition & 1 deletion programs/develop/webpack/plugin-css/css-tools/sass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function maybeUseSass(
'postcss-preset-env',
'postcss-normalize'
]
const projectName = require(path.join(projectPath, 'package.json')).name
const projectName = require(path.join(process.cwd(), 'package.json')).name

await installOptionalDependencies(
projectName,
Expand Down
2 changes: 1 addition & 1 deletion programs/develop/webpack/plugin-css/css-tools/stylelint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function isUsingStylelint(projectPath: string) {
return false
}

const configFile = getStylelintConfigFile(projectPath)
const configFile = getStylelintConfigFile(process.cwd())
const isUsingStylelint = !!configFile

if (isUsingStylelint) {
Expand Down
4 changes: 2 additions & 2 deletions programs/develop/webpack/plugin-css/css-tools/tailwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function isUsingTailwind(projectPath: string) {
return false
}

const configFile = getTailwindConfigFile(projectPath)
const configFile = getTailwindConfigFile(process.cwd())
const packageJson = require(packageJsonPath)

const tailwindAsDevDep =
Expand Down Expand Up @@ -60,7 +60,7 @@ export function getTailwindConfigFile(projectPath: string) {
}

export async function maybeUseTailwind(projectPath: string) {
const projectName = require(path.join(projectPath, 'package.json')).name
const projectName = require(path.join(process.cwd(), 'package.json')).name

if (!isUsingTailwind(projectPath)) return []
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class HandleCommonErrors {
}
})
}
)
)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function isUsingBabel(projectPath: string): boolean {

const isUsingBabel =
babelConfigFiles.some((file) =>
fs.existsSync(path.join(projectPath, file))
fs.existsSync(path.join(process.cwd(), file))
) ||
!!babelAsDevDep ||
!!babelAsDep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function isUsingTypeScript(projectPath: string) {
return false
}

const configFile = getUserTypeScriptConfigFile(projectPath)
const configFile = getUserTypeScriptConfigFile(process.cwd())
const packageJson = require(packageJsonPath)
const manifest = require(path.join(projectPath, 'manifest.json'))
const manifestName = manifest.name || 'Extension.js'
Expand All @@ -40,7 +40,7 @@ export function isUsingTypeScript(projectPath: string) {
}
} else {
console.log(messages.creatingTSConfig(manifest))
writeTsConfig(projectPath)
writeTsConfig(process.cwd())
}
}

Expand All @@ -63,8 +63,6 @@ export function defaultTypeScriptConfig(projectPath: string, _opts?: any) {
// Issue an error if a program tries to include a file by a casing
// different from the casing on disk.
forceConsistentCasingInFileNames: true,
// Report errors on unused local variables.
// inlineSources: false,
// Controls how JSX constructs are emitted in JavaScript files.
// This only affects output of JS files that started in .tsx files.
jsx: isUsingJSFramework(projectPath) ? 'react-jsx' : 'preserve',
Expand All @@ -75,10 +73,7 @@ export function defaultTypeScriptConfig(projectPath: string, _opts?: any) {
moduleResolution: 'node',
// Use ES modules, which are the standard in modern browsers
module: 'esnext',
// Report errors on unused local variables.
// noUnusedLocals: false,
// Report errors on unused parameters in functions.
// noUnusedParameters: false,
noEmit: true,
// Allow importing '.json' files
resolveJsonModule: true,
// Enable all strict type-checking options
Expand All @@ -87,9 +82,10 @@ export function defaultTypeScriptConfig(projectPath: string, _opts?: any) {
target: 'esnext',
// Ensure each file can be safely transpiled without relying
// on other imports
isolatedModules: false,
isolatedModules: true,
skipLibCheck: true
},
include: ['**/*.ts', '**/*.tsx'],
exclude: ['node_modules', 'dist']
}
}
Expand Down

0 comments on commit 4c29062

Please sign in to comment.