-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): introduce nx import #26847
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { | ||
checkFilesExist, | ||
cleanupProject, | ||
getSelectedPackageManager, | ||
newProject, | ||
runCLI, | ||
updateJson, | ||
updateFile, | ||
e2eCwd, | ||
} from '@nx/e2e/utils'; | ||
import { mkdirSync, rmdirSync } from 'fs'; | ||
import { execSync } from 'node:child_process'; | ||
import { join } from 'path'; | ||
|
||
describe('Nx Import', () => { | ||
let proj: string; | ||
const tempImportE2ERoot = join(e2eCwd, 'nx-import'); | ||
beforeAll(() => { | ||
proj = newProject({ | ||
packages: ['@nx/js'], | ||
unsetProjectNameAndRootFormat: false, | ||
}); | ||
|
||
if (getSelectedPackageManager() === 'pnpm') { | ||
updateFile( | ||
'pnpm-workspace.yaml', | ||
`packages: | ||
- 'projects/*' | ||
` | ||
); | ||
} else { | ||
updateJson('package.json', (json) => { | ||
json.workspaces = ['projects/*']; | ||
return json; | ||
}); | ||
} | ||
|
||
try { | ||
rmdirSync(join(tempImportE2ERoot)); | ||
} catch {} | ||
}); | ||
afterAll(() => cleanupProject()); | ||
|
||
it('should be able to import a vite app', () => { | ||
mkdirSync(join(tempImportE2ERoot), { recursive: true }); | ||
const tempViteProjectName = 'created-vite-app'; | ||
execSync( | ||
`npx create-vite@latest ${tempViteProjectName} --template react-ts`, | ||
{ | ||
cwd: tempImportE2ERoot, | ||
} | ||
); | ||
const tempViteProjectPath = join(tempImportE2ERoot, tempViteProjectName); | ||
execSync(`git init`, { | ||
cwd: tempViteProjectPath, | ||
}); | ||
execSync(`git add .`, { | ||
cwd: tempViteProjectPath, | ||
}); | ||
execSync(`git commit -am "initial commit"`, { | ||
cwd: tempViteProjectPath, | ||
}); | ||
execSync(`git checkout -b main`, { | ||
cwd: tempViteProjectPath, | ||
}); | ||
|
||
const remote = tempViteProjectPath; | ||
const ref = 'main'; | ||
const source = '.'; | ||
const directory = 'projects/vite-app'; | ||
|
||
runCLI( | ||
`import ${remote} ${directory} --ref ${ref} --source ${source} --no-interactive`, | ||
{ | ||
verbose: true, | ||
} | ||
); | ||
|
||
checkFilesExist( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make some assertion about the git history of the project files? I trust that it is working, but just to keep it that way. |
||
'projects/vite-app/.gitignore', | ||
'projects/vite-app/package.json', | ||
'projects/vite-app/index.html', | ||
'projects/vite-app/vite.config.ts', | ||
'projects/vite-app/src/main.tsx', | ||
'projects/vite-app/src/App.tsx' | ||
); | ||
runCLI(`vite:build created-vite-app`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { CommandModule } from 'yargs'; | ||
import { linkToNxDevAndExamples } from '../yargs-utils/documentation'; | ||
import { withVerbose } from '../yargs-utils/shared-options'; | ||
import { handleErrors } from '../../utils/params'; | ||
|
||
export const yargsImportCommand: CommandModule = { | ||
command: 'import [sourceRemoteUrl] [destination]', | ||
describe: false, | ||
builder: (yargs) => | ||
linkToNxDevAndExamples( | ||
withVerbose( | ||
yargs | ||
.positional('sourceRemoteUrl', { | ||
type: 'string', | ||
description: 'The remote URL of the source to import', | ||
}) | ||
.positional('destination', { | ||
type: 'string', | ||
description: | ||
'The directory in the current workspace to import into', | ||
}) | ||
.option('source', { | ||
type: 'string', | ||
description: | ||
'The directory in the source repository to import from', | ||
}) | ||
.option('ref', { | ||
type: 'string', | ||
description: 'The branch from the source repository to import', | ||
}) | ||
.option('interactive', { | ||
type: 'boolean', | ||
description: 'Interactive mode', | ||
default: true, | ||
}) | ||
), | ||
'import' | ||
), | ||
handler: async (args) => { | ||
const exitCode = await handleErrors( | ||
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true', | ||
async () => { | ||
return (await import('./import')).importHandler(args as any); | ||
} | ||
); | ||
process.exit(exitCode); | ||
}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create an extra commit or two? Just want to be safe :)