@@ -53253,12 +53253,14 @@ const read_1 = __importDefault(__nccwpck_require__(1746));
5325353253const fs_extra_1 = __importDefault(__nccwpck_require__(77));
5325453254const resolve_from_1 = __importDefault(__nccwpck_require__(1345));
5325553255const apis_1 = __importDefault(__nccwpck_require__(6500));
53256+ const utils_1 = __nccwpck_require__(3927);
5325653257const file_1 = __nccwpck_require__(398);
5325753258const npm_1 = __nccwpck_require__(6824);
5325853259const publish_1 = __nccwpck_require__(9459);
5325953260const cwd = process.cwd();
5326053261function main() {
5326153262 return __awaiter(this, void 0, void 0, function* () {
53263+ var _a;
5326253264 // npmrc 설정
5326353265 yield (0, npm_1.setNpmRc)();
5326453266 const { pullFetchers, issueFetchers } = (0, apis_1.default)();
@@ -53271,18 +53273,27 @@ function main() {
5327153273 yield issueFetchers.addComment('올바른 카나리 버전 배포를 위해 detect version을 명시해주세요');
5327253274 return;
5327353275 }
53276+ const changedFiles = yield (0, utils_1.getChangedAllFiles)({
53277+ pullNumber: pullRequestInfo.number,
53278+ });
5327453279 // 변경된 패키지 파일을 가져온다
5327553280 const packagesDir = core.getInput('packages_dir');
53281+ const excludes = (_a = core.getInput('excludes')) !== null && _a !== void 0 ? _a : '';
5327653282 const changedPackageInfos = yield (0, file_1.getChangedPackages)({
53277- pullNumber: pullRequestInfo.number,
5327853283 packagesDir: packagesDir.split(','),
53284+ excludes: excludes.split(','),
53285+ changedFiles,
5327953286 });
5328053287 if (changedPackageInfos.length === 0) {
5328153288 core.info('변경된 패키지가 없습니다.');
5328253289 return;
5328353290 }
53284- // 변경사항외 다른 패키지들의 배포를 막습니다.
53285- yield (0, file_1.protectUnchangedPackages)(changedPackageInfos);
53291+ yield Promise.all([
53292+ // 이번 변경건과 관련없는 모든 .changeset/*.md 파일을 제거한다.
53293+ (0, file_1.removeChangesetMdFiles)({ changedFiles }),
53294+ // 변경사항외 다른 패키지들의 배포를 막습니다.
53295+ (0, file_1.protectUnchangedPackages)(changedPackageInfos),
53296+ ]);
5328653297 // 패키지 변경 버전 반영
5328753298 yield (0, exec_1.exec)('node', [(0, resolve_from_1.default)(cwd, '@changesets/cli/bin.js'), 'version'], {
5328853299 cwd,
@@ -53383,26 +53394,31 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
5338353394exports.getChangedPackages = getChangedPackages;
5338453395exports.getAllPackageJSON = getAllPackageJSON;
5338553396exports.protectUnchangedPackages = protectUnchangedPackages;
53397+ exports.removeChangesetMdFiles = removeChangesetMdFiles;
5338653398const core = __importStar(__nccwpck_require__(6108));
5338753399const fast_glob_1 = __importDefault(__nccwpck_require__(6014));
5338853400const fs_extra_1 = __importDefault(__nccwpck_require__(77));
5338953401const utils_1 = __nccwpck_require__(3927);
5339053402function getChangedPackages(_a) {
53391- return __awaiter(this, arguments, void 0, function* ({ pullNumber, packagesDir }) {
53392- const changedFiles = yield (0, utils_1.getChangedAllFiles)({
53393- pullNumber,
53394- });
53403+ return __awaiter(this, arguments, void 0, function* ({ changedFiles, packagesDir, excludes, }) {
53404+ const isIncludedRoot = packagesDir.includes('.') === true;
53405+ const targetDirectories = packagesDir.filter((packagename) => packagename !== '.');
5339553406 const changedPackages = changedFiles.reduce((acc, { filename }) => {
53396- const isTargetDirectories = packagesDir.some((packageDir) => filename.includes(`${packageDir}/`));
53397- const isMarkdownFile = filename.endsWith('.md');
53398- if (isTargetDirectories && !isMarkdownFile) {
53399- const [packageRoot, packageName] = filename.split('/');
53400- const packageJsonPath = [packageRoot, packageName, 'package.json'].join('/');
53401- acc.push(packageJsonPath);
53407+ const 패키지대상인가 = isIncludedRoot || targetDirectories.some((packageDir) => filename.includes(`${packageDir}/`));
53408+ const 마크다운파일인가 = filename.endsWith('.md');
53409+ const 제외대상인가 = excludes.some((exclude) => {
53410+ return filename === exclude || filename.startsWith(`${exclude}`);
53411+ });
53412+ if (패키지대상인가 && !마크다운파일인가 && !제외대상인가) {
53413+ const packageJsonPath = isIncludedRoot ? 'package.json' : (0, utils_1.findNearestPackageJson)(filename);
53414+ if (packageJsonPath != null) {
53415+ acc.add(packageJsonPath);
53416+ }
5340253417 }
5340353418 return acc;
53404- }, []);
53405- return [...new Set(changedPackages)];
53419+ }, new Set());
53420+ console.log('필터링된 packages', Array.from(changedPackages)); // eslint-disable-line
53421+ return Array.from(changedPackages);
5340653422 });
5340753423}
5340853424function getAllPackageJSON() {
@@ -53426,6 +53442,17 @@ function protectUnchangedPackages(changedPackages) {
5342653442 }
5342753443 });
5342853444}
53445+ function removeChangesetMdFiles(_a) {
53446+ return __awaiter(this, arguments, void 0, function* ({ changedFiles, }) {
53447+ const markdownPaths = yield (0, fast_glob_1.default)('.changeset/*.md');
53448+ return Promise.all(markdownPaths.map((markdownPath) => __awaiter(this, void 0, void 0, function* () {
53449+ if (changedFiles.find(({ filename }) => filename === markdownPath) == null) {
53450+ console.log(`PR과 관련없는 ${markdownPath} 제거`); // eslint-disable-line
53451+ yield fs_extra_1.default.remove(markdownPath);
53452+ }
53453+ })));
53454+ });
53455+ }
5342953456
5343053457
5343153458/***/ }),
@@ -53818,10 +53845,16 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
5381853845 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
5381953846 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
5382053847};
53848+ var __importDefault = (this && this.__importDefault) || function (mod) {
53849+ return (mod && mod.__esModule) ? mod : { "default": mod };
53850+ };
5382153851Object.defineProperty(exports, "__esModule", ({ value: true }));
5382253852exports.getChangedAllFiles = getChangedAllFiles;
53853+ exports.findNearestPackageJson = findNearestPackageJson;
53854+ const path_1 = __importDefault(__nccwpck_require__(1017));
5382353855const core = __importStar(__nccwpck_require__(6108));
5382453856const github = __importStar(__nccwpck_require__(1645));
53857+ const fs_extra_1 = __importDefault(__nccwpck_require__(77));
5382553858const utils_1 = __nccwpck_require__(3927);
5382653859function getChangedAllFiles(_a) {
5382753860 return __awaiter(this, arguments, void 0, function* ({ pullNumber }) {
@@ -53853,6 +53886,17 @@ function getChangedAllFiles(_a) {
5385353886 return changedFiles;
5385453887 });
5385553888}
53889+ function findNearestPackageJson(filePath) {
53890+ let currentDir = path_1.default.dirname(filePath);
53891+ while (currentDir !== path_1.default.parse(currentDir).root) {
53892+ const packageJsonPath = path_1.default.join(currentDir, 'package.json');
53893+ if (fs_extra_1.default.existsSync(packageJsonPath)) {
53894+ return packageJsonPath;
53895+ }
53896+ currentDir = path_1.default.dirname(currentDir);
53897+ }
53898+ return undefined;
53899+ }
5385653900
5385753901
5385853902/***/ }),
0 commit comments